@@ -0,0 +1,152 @@
1+import ./make-test-python.nix ({ pkgs, lib, ...} : {
2+ name = "wiki-js";
3+ meta = with pkgs.lib.maintainers; {
4+ maintainers = [ ma27 ];
5+ };
6+
7+ machine = { pkgs, ... }: {
8+ virtualisation.memorySize = 2048;
9+ services.wiki-js = {
10+ enable = true;
11+ settings.db.host = "/run/postgresql";
12+ settings.db.user = "wiki-js";
13+ settings.logLevel = "debug";
14+ };
15+ services.postgresql = {
16+ enable = true;
17+ ensureDatabases = [ "wiki" ];
18+ ensureUsers = [
19+ { name = "wiki-js";
20+ ensurePermissions."DATABASE wiki" = "ALL PRIVILEGES";
21+ }
22+ ];
23+ };
24+ systemd.services.wiki-js = {
25+ requires = [ "postgresql.service" ];
26+ after = [ "postgresql.service" ];
27+ };
28+ environment.systemPackages = with pkgs; [ jq ];
29+ };
30+
31+ testScript = let
32+ payloads.finalize = pkgs.writeText "finalize.json" (builtins.toJSON {
33+ adminEmail = "webmaster@example.com";
34+ adminPassword = "notapassword";
35+ adminPasswordConfirm = "notapassword";
36+ siteUrl = "http://localhost:3000";
37+ telemetry = false;
38+ });
39+ payloads.login = pkgs.writeText "login.json" (builtins.toJSON [{
40+ operationName = null;
41+ extensions = {};
42+ query = ''
43+ mutation ($username: String!, $password: String!, $strategy: String!) {
44+ authentication {
45+ login(username: $username, password: $password, strategy: $strategy) {
46+ responseResult {
47+ succeeded
48+ errorCode
49+ slug
50+ message
51+ __typename
52+ }
53+ jwt
54+ mustChangePwd
55+ mustProvideTFA
56+ mustSetupTFA
57+ continuationToken
58+ redirect
59+ tfaQRImage
60+ __typename
61+ }
62+ __typename
63+ }
64+ }
65+ '';
66+ variables = {
67+ password = "notapassword";
68+ strategy = "local";
69+ username = "webmaster@example.com";
70+ };
71+ }]);
72+ payloads.content = pkgs.writeText "content.json" (builtins.toJSON [{
73+ extensions = {};
74+ operationName = null;
75+ query = ''
76+ mutation ($content: String!, $description: String!, $editor: String!, $isPrivate: Boolean!, $isPublished: Boolean!, $locale: String!, $path: String!, $publishEndDate: Date, $publishStartDate: Date, $scriptCss: String, $scriptJs: String, $tags: [String]!, $title: String!) {
77+ pages {
78+ create(content: $content, description: $description, editor: $editor, isPrivate: $isPrivate, isPublished: $isPublished, locale: $locale, path: $path, publishEndDate: $publishEndDate, publishStartDate: $publishStartDate, scriptCss: $scriptCss, scriptJs: $scriptJs, tags: $tags, title: $title) {
79+ responseResult {
80+ succeeded
81+ errorCode
82+ slug
83+ message
84+ __typename
85+ }
86+ page {
87+ id
88+ updatedAt
89+ __typename
90+ }
91+ __typename
92+ }
93+ __typename
94+ }
95+ }
96+ '';
97+ variables = {
98+ content = "# Header\n\nHello world!";
99+ description = "";
100+ editor = "markdown";
101+ isPrivate = false;
102+ isPublished = true;
103+ locale = "en";
104+ path = "home";
105+ publishEndDate = "";
106+ publishStartDate = "";
107+ scriptCss = "";
108+ scriptJs = "";
109+ tags = [];
110+ title = "Hello world";
111+ };
112+ }]);
113+ in ''
114+ machine.start()
115+ machine.wait_for_unit("multi-user.target")
116+ machine.wait_for_open_port(3000)
117+
118+ machine.succeed("curl -sSf localhost:3000")
119+
120+ with subtest("Setup"):
121+ result = machine.succeed(
122+ "set -o pipefail; curl -sSf localhost:3000/finalize -X POST -d "
123+ + "@${payloads.finalize} -H 'Content-Type: application/json' "
124+ + "| jq .ok | xargs echo"
125+ )
126+ assert result.strip() == "true", f"Expected true, got {result}"
127+
128+ # During the setup the service gets restarted, so we use this
129+ # to check if the setup is done.
130+ machine.wait_until_fails("curl -sSf localhost:3000")
131+ machine.wait_until_succeeds("curl -sSf localhost:3000")
132+
133+ with subtest("Base functionality"):
134+ auth = machine.succeed(
135+ "set -o pipefail; curl -sSf localhost:3000/graphql -X POST "
136+ + "-d @${payloads.login} -H 'Content-Type: application/json' "
137+ + "| jq '.[0].data.authentication.login.jwt' | xargs echo"
138+ ).strip()
139+
140+ assert auth
141+
142+ create = machine.succeed(
143+ "set -o pipefail; curl -sSf localhost:3000/graphql -X POST "
144+ + "-d @${payloads.content} -H 'Content-Type: application/json' "
145+ + f"-H 'Authorization: Bearer {auth}' "
146+ + "| jq '.[0].data.pages.create.responseResult.succeeded'|xargs echo"
147+ )
148+ assert create.strip() == "true", f"Expected true, got {create}"
149+
150+ machine.shutdown()
151+ '';
152+})