2024-04-19 20:36:15 -04:00
|
|
|
import { LoginResponseDto } from '@immich/sdk';
|
2024-02-19 22:34:18 -05:00
|
|
|
import { createUserDto } from 'src/fixtures';
|
|
|
|
|
import { errorDto } from 'src/responses';
|
2024-03-07 10:14:36 -05:00
|
|
|
import { app, utils } from 'src/utils';
|
2023-09-01 22:01:54 -04:00
|
|
|
import request from 'supertest';
|
2024-02-19 22:34:18 -05:00
|
|
|
import { beforeAll, describe, expect, it } from 'vitest';
|
2023-09-01 22:01:54 -04:00
|
|
|
|
2024-02-19 22:34:18 -05:00
|
|
|
describe('/server-info', () => {
|
2023-11-14 20:08:22 -05:00
|
|
|
let admin: LoginResponseDto;
|
|
|
|
|
let nonAdmin: LoginResponseDto;
|
2023-09-01 22:01:54 -04:00
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
2024-03-07 10:14:36 -05:00
|
|
|
await utils.resetDatabase();
|
|
|
|
|
admin = await utils.adminSetup({ onboarding: false });
|
|
|
|
|
nonAdmin = await utils.userSetup(admin.accessToken, createUserDto.user1);
|
2023-09-01 22:01:54 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('GET /server-info', () => {
|
|
|
|
|
it('should require authentication', async () => {
|
2024-02-19 22:34:18 -05:00
|
|
|
const { status, body } = await request(app).get('/server-info');
|
2023-09-01 22:01:54 -04:00
|
|
|
expect(status).toBe(401);
|
2024-02-19 22:34:18 -05:00
|
|
|
expect(body).toEqual(errorDto.unauthorized);
|
2023-09-01 22:01:54 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should return the disk information', async () => {
|
2024-02-19 22:34:18 -05:00
|
|
|
const { status, body } = await request(app)
|
2023-11-14 20:08:22 -05:00
|
|
|
.get('/server-info')
|
|
|
|
|
.set('Authorization', `Bearer ${admin.accessToken}`);
|
2023-09-01 22:01:54 -04:00
|
|
|
expect(status).toBe(200);
|
|
|
|
|
expect(body).toEqual({
|
|
|
|
|
diskAvailable: expect.any(String),
|
|
|
|
|
diskAvailableRaw: expect.any(Number),
|
|
|
|
|
diskSize: expect.any(String),
|
|
|
|
|
diskSizeRaw: expect.any(Number),
|
|
|
|
|
diskUsagePercentage: expect.any(Number),
|
|
|
|
|
diskUse: expect.any(String),
|
|
|
|
|
diskUseRaw: expect.any(Number),
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('GET /server-info/ping', () => {
|
|
|
|
|
it('should respond with pong', async () => {
|
2024-02-19 22:34:18 -05:00
|
|
|
const { status, body } = await request(app).get('/server-info/ping');
|
2023-09-01 22:01:54 -04:00
|
|
|
expect(status).toBe(200);
|
|
|
|
|
expect(body).toEqual({ res: 'pong' });
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('GET /server-info/version', () => {
|
|
|
|
|
it('should respond with the server version', async () => {
|
2024-02-19 22:34:18 -05:00
|
|
|
const { status, body } = await request(app).get('/server-info/version');
|
2023-09-01 22:01:54 -04:00
|
|
|
expect(status).toBe(200);
|
|
|
|
|
expect(body).toEqual({
|
|
|
|
|
major: expect.any(Number),
|
|
|
|
|
minor: expect.any(Number),
|
|
|
|
|
patch: expect.any(Number),
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('GET /server-info/features', () => {
|
|
|
|
|
it('should respond with the server features', async () => {
|
2024-02-19 22:34:18 -05:00
|
|
|
const { status, body } = await request(app).get('/server-info/features');
|
2023-09-01 22:01:54 -04:00
|
|
|
expect(status).toBe(200);
|
|
|
|
|
expect(body).toEqual({
|
2024-02-19 22:34:18 -05:00
|
|
|
smartSearch: false,
|
2024-01-09 23:04:16 -05:00
|
|
|
configFile: false,
|
2024-02-19 22:34:18 -05:00
|
|
|
facialRecognition: false,
|
2023-09-08 22:51:46 -04:00
|
|
|
map: true,
|
2024-01-09 23:04:16 -05:00
|
|
|
reverseGeocoding: true,
|
2023-09-01 22:01:54 -04:00
|
|
|
oauth: false,
|
|
|
|
|
oauthAutoLaunch: false,
|
|
|
|
|
passwordLogin: true,
|
2023-12-08 11:15:46 -05:00
|
|
|
search: true,
|
2023-09-01 22:01:54 -04:00
|
|
|
sidecar: true,
|
2023-10-06 07:01:14 +00:00
|
|
|
trash: true,
|
2024-05-02 16:43:18 +02:00
|
|
|
email: false,
|
2023-09-01 22:01:54 -04:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2023-09-08 22:51:46 -04:00
|
|
|
describe('GET /server-info/config', () => {
|
|
|
|
|
it('should respond with the server configuration', async () => {
|
2024-02-19 22:34:18 -05:00
|
|
|
const { status, body } = await request(app).get('/server-info/config');
|
2023-09-08 22:51:46 -04:00
|
|
|
expect(status).toBe(200);
|
|
|
|
|
expect(body).toEqual({
|
|
|
|
|
loginPageMessage: '',
|
|
|
|
|
oauthButtonText: 'Login with OAuth',
|
2023-10-06 07:01:14 +00:00
|
|
|
trashDays: 30,
|
2024-03-06 00:45:40 -05:00
|
|
|
userDeleteDelay: 7,
|
2023-10-11 04:37:13 +02:00
|
|
|
isInitialized: true,
|
2024-01-03 21:54:48 -05:00
|
|
|
externalDomain: '',
|
2024-01-03 23:28:32 -06:00
|
|
|
isOnboarded: false,
|
2023-09-08 22:51:46 -04:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2023-11-03 21:33:15 -04:00
|
|
|
describe('GET /server-info/statistics', () => {
|
2023-09-01 22:01:54 -04:00
|
|
|
it('should require authentication', async () => {
|
2024-02-29 11:26:55 -05:00
|
|
|
const { status, body } = await request(app).get('/server-info/statistics');
|
2023-09-01 22:01:54 -04:00
|
|
|
expect(status).toBe(401);
|
2024-02-19 22:34:18 -05:00
|
|
|
expect(body).toEqual(errorDto.unauthorized);
|
2023-09-01 22:01:54 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should only work for admins', async () => {
|
2024-02-19 22:34:18 -05:00
|
|
|
const { status, body } = await request(app)
|
2023-11-03 21:33:15 -04:00
|
|
|
.get('/server-info/statistics')
|
2023-11-14 20:08:22 -05:00
|
|
|
.set('Authorization', `Bearer ${nonAdmin.accessToken}`);
|
2023-09-01 22:01:54 -04:00
|
|
|
expect(status).toBe(403);
|
2024-02-19 22:34:18 -05:00
|
|
|
expect(body).toEqual(errorDto.forbidden);
|
2023-09-01 22:01:54 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should return the server stats', async () => {
|
2024-02-19 22:34:18 -05:00
|
|
|
const { status, body } = await request(app)
|
2023-11-03 21:33:15 -04:00
|
|
|
.get('/server-info/statistics')
|
2023-11-14 20:08:22 -05:00
|
|
|
.set('Authorization', `Bearer ${admin.accessToken}`);
|
2023-09-01 22:01:54 -04:00
|
|
|
expect(status).toBe(200);
|
|
|
|
|
expect(body).toEqual({
|
|
|
|
|
photos: 0,
|
|
|
|
|
usage: 0,
|
|
|
|
|
usageByUser: [
|
|
|
|
|
{
|
2024-01-12 18:43:36 -06:00
|
|
|
quotaSizeInBytes: null,
|
2023-09-01 22:01:54 -04:00
|
|
|
photos: 0,
|
|
|
|
|
usage: 0,
|
2023-11-11 20:03:32 -05:00
|
|
|
userName: 'Immich Admin',
|
2023-11-14 20:08:22 -05:00
|
|
|
userId: admin.userId,
|
|
|
|
|
videos: 0,
|
|
|
|
|
},
|
|
|
|
|
{
|
2024-01-12 18:43:36 -06:00
|
|
|
quotaSizeInBytes: null,
|
2023-11-14 20:08:22 -05:00
|
|
|
photos: 0,
|
|
|
|
|
usage: 0,
|
|
|
|
|
userName: 'User 1',
|
|
|
|
|
userId: nonAdmin.userId,
|
2023-09-01 22:01:54 -04:00
|
|
|
videos: 0,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
videos: 0,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('GET /server-info/media-types', () => {
|
|
|
|
|
it('should return accepted media types', async () => {
|
2024-02-29 11:26:55 -05:00
|
|
|
const { status, body } = await request(app).get('/server-info/media-types');
|
2023-09-01 22:01:54 -04:00
|
|
|
expect(status).toBe(200);
|
|
|
|
|
expect(body).toEqual({
|
|
|
|
|
sidecar: ['.xmp'],
|
|
|
|
|
image: expect.any(Array),
|
|
|
|
|
video: expect.any(Array),
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2023-10-25 15:13:05 -07:00
|
|
|
|
|
|
|
|
describe('GET /server-info/theme', () => {
|
|
|
|
|
it('should respond with the server theme', async () => {
|
2024-02-19 22:34:18 -05:00
|
|
|
const { status, body } = await request(app).get('/server-info/theme');
|
2023-10-25 15:13:05 -07:00
|
|
|
expect(status).toBe(200);
|
|
|
|
|
expect(body).toEqual({
|
2023-10-26 19:32:33 -07:00
|
|
|
customCss: '',
|
2023-10-25 15:13:05 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2023-09-01 22:01:54 -04:00
|
|
|
});
|