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