about summary refs log tree commit diff
path: root/nixos/tests/web-apps/immich.nix
blob: f03b9290f7a591077a0e2f0173a8e923e2be563d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import ../make-test-python.nix (
  { ... }:
  {
    name = "immich-nixos";

    nodes.machine =
      { pkgs, ... }:
      {
        # These tests need a little more juice
        virtualisation = {
          cores = 2;
          memorySize = 2048;
          diskSize = 4096;
        };

        environment.systemPackages = with pkgs; [ immich-cli ];

        services.immich = {
          enable = true;
          environment.IMMICH_LOG_LEVEL = "verbose";
        };
      };

    testScript = ''
      import json

      machine.wait_for_unit("immich-server.service")

      machine.wait_for_open_port(3001) # Server
      machine.wait_for_open_port(3003) # Machine learning
      machine.succeed("curl --fail http://localhost:3001/")

      machine.succeed("""
        curl -H 'Content-Type: application/json' --data '{ "email": "test@example.com", "name": "Admin", "password": "admin" }' -X POST http://localhost:3001/api/auth/admin-sign-up
      """)
      res = machine.succeed("""
        curl -H 'Content-Type: application/json' --data '{ "email": "test@example.com", "password": "admin" }' -X POST http://localhost:3001/api/auth/login
      """)
      token = json.loads(res)['accessToken']

      res = machine.succeed("""
        curl -H 'Content-Type: application/json' -H 'Cookie: immich_access_token=%s' --data '{ "name": "API Key", "permissions": ["all"] }' -X POST http://localhost:3001/api/api-keys
      """ % token)
      key = json.loads(res)['secret']

      machine.succeed(f"immich login http://localhost:3001/api {key}")
      res = machine.succeed("immich server-info")
      print(res)
    '';
  }
)