|
| 1 | +import { LoginResponseDto } from '@immich/sdk'; |
| 2 | +import { createUserDto } from 'src/fixtures'; |
| 3 | +import { errorDto } from 'src/responses'; |
| 4 | +import { app, utils } from 'src/utils'; |
| 5 | +import request from 'supertest'; |
| 6 | +import { beforeAll, describe, expect, it } from 'vitest'; |
| 7 | + |
| 8 | +describe('/server', () => { |
| 9 | + let admin: LoginResponseDto; |
| 10 | + let nonAdmin: LoginResponseDto; |
| 11 | + |
| 12 | + beforeAll(async () => { |
| 13 | + await utils.resetDatabase(); |
| 14 | + admin = await utils.adminSetup({ onboarding: false }); |
| 15 | + nonAdmin = await utils.userSetup(admin.accessToken, createUserDto.user1); |
| 16 | + }); |
| 17 | + |
| 18 | + describe('GET /server/about', () => { |
| 19 | + it('should require authentication', async () => { |
| 20 | + const { status, body } = await request(app).get('/server/about'); |
| 21 | + expect(status).toBe(401); |
| 22 | + expect(body).toEqual(errorDto.unauthorized); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should return about information', async () => { |
| 26 | + const { status, body } = await request(app) |
| 27 | + .get('/server/about') |
| 28 | + .set('Authorization', `Bearer ${admin.accessToken}`); |
| 29 | + expect(status).toBe(200); |
| 30 | + expect(body).toEqual({ |
| 31 | + version: expect.any(String), |
| 32 | + versionUrl: expect.any(String), |
| 33 | + repository: 'immich-app/immich', |
| 34 | + repositoryUrl: 'https://github.com/immich-app/immich', |
| 35 | + build: '1234567890', |
| 36 | + buildUrl: 'https://github.com/immich-app/immich/actions/runs/1234567890', |
| 37 | + buildImage: 'e2e', |
| 38 | + buildImageUrl: 'https://github.com/immich-app/immich/pkgs/container/immich-server', |
| 39 | + sourceRef: 'e2e', |
| 40 | + sourceCommit: 'e2eeeeeeeeeeeeeeeeee', |
| 41 | + sourceUrl: 'https://github.com/immich-app/immich/commit/e2eeeeeeeeeeeeeeeeee', |
| 42 | + nodejs: expect.any(String), |
| 43 | + ffmpeg: expect.any(String), |
| 44 | + imagemagick: expect.any(String), |
| 45 | + libvips: expect.any(String), |
| 46 | + exiftool: expect.any(String), |
| 47 | + }); |
| 48 | + }); |
| 49 | + }); |
| 50 | + |
| 51 | + describe('GET /server/storage', () => { |
| 52 | + it('should require authentication', async () => { |
| 53 | + const { status, body } = await request(app).get('/server/storage'); |
| 54 | + expect(status).toBe(401); |
| 55 | + expect(body).toEqual(errorDto.unauthorized); |
| 56 | + }); |
| 57 | + |
| 58 | + it('should return the disk information', async () => { |
| 59 | + const { status, body } = await request(app) |
| 60 | + .get('/server/storage') |
| 61 | + .set('Authorization', `Bearer ${admin.accessToken}`); |
| 62 | + expect(status).toBe(200); |
| 63 | + expect(body).toEqual({ |
| 64 | + diskAvailable: expect.any(String), |
| 65 | + diskAvailableRaw: expect.any(Number), |
| 66 | + diskSize: expect.any(String), |
| 67 | + diskSizeRaw: expect.any(Number), |
| 68 | + diskUsagePercentage: expect.any(Number), |
| 69 | + diskUse: expect.any(String), |
| 70 | + diskUseRaw: expect.any(Number), |
| 71 | + }); |
| 72 | + }); |
| 73 | + }); |
| 74 | + |
| 75 | + describe('GET /server/ping', () => { |
| 76 | + it('should respond with pong', async () => { |
| 77 | + const { status, body } = await request(app).get('/server/ping'); |
| 78 | + expect(status).toBe(200); |
| 79 | + expect(body).toEqual({ res: 'pong' }); |
| 80 | + }); |
| 81 | + }); |
| 82 | + |
| 83 | + describe('GET /server/version', () => { |
| 84 | + it('should respond with the server version', async () => { |
| 85 | + const { status, body } = await request(app).get('/server/version'); |
| 86 | + expect(status).toBe(200); |
| 87 | + expect(body).toEqual({ |
| 88 | + major: expect.any(Number), |
| 89 | + minor: expect.any(Number), |
| 90 | + patch: expect.any(Number), |
| 91 | + }); |
| 92 | + }); |
| 93 | + }); |
| 94 | + |
| 95 | + describe('GET /server/features', () => { |
| 96 | + it('should respond with the server features', async () => { |
| 97 | + const { status, body } = await request(app).get('/server/features'); |
| 98 | + expect(status).toBe(200); |
| 99 | + expect(body).toEqual({ |
| 100 | + smartSearch: false, |
| 101 | + configFile: false, |
| 102 | + duplicateDetection: false, |
| 103 | + facialRecognition: false, |
| 104 | + map: true, |
| 105 | + reverseGeocoding: true, |
| 106 | + oauth: false, |
| 107 | + oauthAutoLaunch: false, |
| 108 | + passwordLogin: true, |
| 109 | + search: true, |
| 110 | + sidecar: true, |
| 111 | + trash: true, |
| 112 | + email: false, |
| 113 | + }); |
| 114 | + }); |
| 115 | + }); |
| 116 | + |
| 117 | + describe('GET /server/config', () => { |
| 118 | + it('should respond with the server configuration', async () => { |
| 119 | + const { status, body } = await request(app).get('/server/config'); |
| 120 | + expect(status).toBe(200); |
| 121 | + expect(body).toEqual({ |
| 122 | + loginPageMessage: '', |
| 123 | + oauthButtonText: 'Login with OAuth', |
| 124 | + trashDays: 30, |
| 125 | + userDeleteDelay: 7, |
| 126 | + isInitialized: true, |
| 127 | + externalDomain: '', |
| 128 | + isOnboarded: false, |
| 129 | + }); |
| 130 | + }); |
| 131 | + }); |
| 132 | + |
| 133 | + describe('GET /server/statistics', () => { |
| 134 | + it('should require authentication', async () => { |
| 135 | + const { status, body } = await request(app).get('/server/statistics'); |
| 136 | + expect(status).toBe(401); |
| 137 | + expect(body).toEqual(errorDto.unauthorized); |
| 138 | + }); |
| 139 | + |
| 140 | + it('should only work for admins', async () => { |
| 141 | + const { status, body } = await request(app) |
| 142 | + .get('/server/statistics') |
| 143 | + .set('Authorization', `Bearer ${nonAdmin.accessToken}`); |
| 144 | + expect(status).toBe(403); |
| 145 | + expect(body).toEqual(errorDto.forbidden); |
| 146 | + }); |
| 147 | + |
| 148 | + it('should return the server stats', async () => { |
| 149 | + const { status, body } = await request(app) |
| 150 | + .get('/server/statistics') |
| 151 | + .set('Authorization', `Bearer ${admin.accessToken}`); |
| 152 | + expect(status).toBe(200); |
| 153 | + expect(body).toEqual({ |
| 154 | + photos: 0, |
| 155 | + usage: 0, |
| 156 | + usageByUser: [ |
| 157 | + { |
| 158 | + quotaSizeInBytes: null, |
| 159 | + photos: 0, |
| 160 | + usage: 0, |
| 161 | + userName: 'Immich Admin', |
| 162 | + userId: admin.userId, |
| 163 | + videos: 0, |
| 164 | + }, |
| 165 | + { |
| 166 | + quotaSizeInBytes: null, |
| 167 | + photos: 0, |
| 168 | + usage: 0, |
| 169 | + userName: 'User 1', |
| 170 | + userId: nonAdmin.userId, |
| 171 | + videos: 0, |
| 172 | + }, |
| 173 | + ], |
| 174 | + videos: 0, |
| 175 | + }); |
| 176 | + }); |
| 177 | + }); |
| 178 | + |
| 179 | + describe('GET /server/media-types', () => { |
| 180 | + it('should return accepted media types', async () => { |
| 181 | + const { status, body } = await request(app).get('/server/media-types'); |
| 182 | + expect(status).toBe(200); |
| 183 | + expect(body).toEqual({ |
| 184 | + sidecar: ['.xmp'], |
| 185 | + image: expect.any(Array), |
| 186 | + video: expect.any(Array), |
| 187 | + }); |
| 188 | + }); |
| 189 | + }); |
| 190 | + |
| 191 | + describe('GET /server/theme', () => { |
| 192 | + it('should respond with the server theme', async () => { |
| 193 | + const { status, body } = await request(app).get('/server/theme'); |
| 194 | + expect(status).toBe(200); |
| 195 | + expect(body).toEqual({ |
| 196 | + customCss: '', |
| 197 | + }); |
| 198 | + }); |
| 199 | + }); |
| 200 | +}); |
0 commit comments