diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 8f37ebd86f80..d130f9df564d 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -1338,6 +1338,7 @@ in pantalaimon = runTest ./matrix/pantalaimon.nix; pantheon = runTest ./pantheon.nix; paperless = runTest ./paperless.nix; + papra = runTest ./papra.nix; paretosecurity = runTest ./paretosecurity.nix; parsedmarc = handleTest ./parsedmarc { }; part-db = runTest ./web-apps/part-db.nix; diff --git a/nixos/tests/papra.nix b/nixos/tests/papra.nix new file mode 100644 index 000000000000..c34ef6ef2d5e --- /dev/null +++ b/nixos/tests/papra.nix @@ -0,0 +1,76 @@ +{ lib, ... }: +{ + name = "papra"; + meta.maintainers = with lib.maintainers; [ h7x4 ]; + + containers.machine = { + services.papra = { + enable = true; + environment = { + AUTH_IS_EMAIL_VERIFICATION_REQUIRED = false; + AUTH_FIRST_USER_AS_ADMIN = true; + }; + }; + }; + + testScript = + let + serverBaseUrl = "http://localhost:1221"; + cookieJar = "/tmp/papra-cookies"; + + jsonArg = value: "'${lib.escape [ "\"" "'" ] (builtins.toJSON value)}'"; + in + '' + import json + + machine.wait_for_unit("papra.service") + machine.wait_for_open_port(1221) + + with subtest("Health endpoint responds"): + machine.succeed("curl --fail --silent ${serverBaseUrl}/api/health") + + with subtest("Register a user"): + machine.succeed( + "curl --fail --silent" + + " --cookie-jar ${cookieJar}" + + " --json ${ + jsonArg { + email = "admin@example.com"; + password = "correct horse battery staple"; + name = "Admin"; + } + }" + + " ${serverBaseUrl}/api/auth/sign-up/email" + ) + + with subtest("Create an organization"): + organization = json.loads(machine.succeed( + "curl --fail --silent" + + " --cookie ${cookieJar}" + + " --json ${jsonArg { name = "Test Org"; }}" + + " ${serverBaseUrl}/api/organizations" + )) + org_id = organization["organization"]["id"] + assert org_id, f"Expected an organization id, got: {json.dumps(organization)}" + + with subtest("Import a document"): + machine.succeed("echo 'hello from the nixos test' > /tmp/document.txt") + document = json.loads(machine.succeed( + "curl --fail --silent" + + " --cookie ${cookieJar}" + + " --form file=@/tmp/document.txt" + + f" ${serverBaseUrl}/api/organizations/{org_id}/documents" + )) + document_id = document["document"]["id"] + assert document_id, f"Expected a document id, got: {json.dumps(document)}" + + with subtest("Retrieve the imported document"): + machine.succeed( + "curl --fail --silent" + + " --cookie ${cookieJar}" + + f" ${serverBaseUrl}/api/organizations/{org_id}/documents/{document_id}/file" + + " --output /tmp/retrieved-document.txt" + ) + machine.succeed("diff /tmp/document.txt /tmp/retrieved-document.txt") + ''; +} diff --git a/pkgs/by-name/pa/papra/package.nix b/pkgs/by-name/pa/papra/package.nix index ec8af4b4e1da..70bae8dc7265 100644 --- a/pkgs/by-name/pa/papra/package.nix +++ b/pkgs/by-name/pa/papra/package.nix @@ -14,6 +14,7 @@ python3, nix-update-script, tsx, + nixosTests, }: let pnpm = pnpm_11.override { nodejs-slim = nodejs-slim_26; }; @@ -95,7 +96,10 @@ stdenv.mkDerivation (finalAttrs: { runHook postInstall ''; - passthru.updateScript = nix-update-script { }; + passthru = { + updateScript = nix-update-script { }; + tests.nixos = nixosTests.papra; + }; meta = { description = "Open-source document management platform designed to help you organize, secure, and archive your files effortlessly.";