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