1{ pkgs, ... }:
2{
3 name = "kavita";
4 meta = with pkgs.lib.maintainers; {
5 maintainers = [ misterio77 ];
6 };
7
8 nodes = {
9 kavita =
10 { config, pkgs, ... }:
11 {
12 services.kavita = {
13 enable = true;
14 tokenKeyFile = builtins.toFile "kavita.key" "d26ba694b455271a8872415830fb7b5c58f8da98f9ef7f58b2ca4c34bd406512";
15 };
16 };
17 };
18
19 testScript =
20 let
21 regUrl = "http://kavita:5000/api/Account/register";
22 loginUrl = "http://kavita:5000/api/Account/login";
23 localeUrl = "http://kavita:5000/api/locale";
24 in
25 ''
26 import json
27
28 kavita.start
29 kavita.wait_for_unit("kavita.service")
30
31 # Check that static assets are working
32 kavita.wait_until_succeeds("curl http://kavita:5000/site.webmanifest | grep Kavita")
33
34 # Check that registration is working
35 kavita.succeed("""curl -fX POST ${regUrl} --json '{"username": "foo", "password": "correcthorsebatterystaple"}'""")
36 # But only for the first one
37 kavita.fail("""curl -fX POST ${regUrl} --json '{"username": "foo", "password": "correcthorsebatterystaple"}'""")
38
39 # Log in and retrieve token
40 session = json.loads(kavita.succeed("""curl -fX POST ${loginUrl} --json '{"username": "foo", "password": "correcthorsebatterystaple"}'"""))
41 # Check list of locales
42 locales = json.loads(kavita.succeed(f"curl -fX GET ${localeUrl} -H 'Authorization: Bearer {session['token']}'"))
43 assert len(locales) > 0, "expected a list of locales"
44 '';
45}