2023-09-02 04:01:54 +02:00
|
|
|
import { LoginResponseDto } from '@app/domain';
|
2023-10-06 23:32:28 +02:00
|
|
|
import { ServerInfoController } from '@app/immich';
|
2023-09-11 17:56:38 +02:00
|
|
|
import { api } from '@test/api';
|
2023-11-15 03:31:06 +02:00
|
|
|
import { errorStub, userDto } from '@test/fixtures';
|
2023-10-19 00:02:42 +02:00
|
|
|
import { testApp } from '@test/test-utils';
|
2023-09-02 04:01:54 +02:00
|
|
|
import request from 'supertest';
|
|
|
|
|
|
|
|
describe(`${ServerInfoController.name} (e2e)`, () => {
|
|
|
|
let server: any;
|
2023-11-15 03:08:22 +02:00
|
|
|
let admin: LoginResponseDto;
|
|
|
|
let nonAdmin: LoginResponseDto;
|
2023-09-02 04:01:54 +02:00
|
|
|
|
|
|
|
beforeAll(async () => {
|
2023-10-19 00:02:42 +02:00
|
|
|
[server] = await testApp.create();
|
2023-11-15 03:08:22 +02:00
|
|
|
|
2023-11-15 03:31:06 +02:00
|
|
|
await testApp.reset();
|
2023-11-15 03:08:22 +02:00
|
|
|
await api.authApi.adminSignUp(server);
|
|
|
|
admin = await api.authApi.adminLogin(server);
|
2023-11-15 03:31:06 +02:00
|
|
|
await api.userApi.create(server, admin.accessToken, userDto.user1);
|
|
|
|
nonAdmin = await api.authApi.login(server, userDto.user1);
|
2023-10-19 00:02:42 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
await testApp.teardown();
|
2023-09-02 04:01:54 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('GET /server-info', () => {
|
|
|
|
it('should require authentication', async () => {
|
|
|
|
const { status, body } = await request(server).get('/server-info');
|
|
|
|
expect(status).toBe(401);
|
|
|
|
expect(body).toEqual(errorStub.unauthorized);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return the disk information', async () => {
|
2023-11-15 03:08:22 +02:00
|
|
|
const { status, body } = await request(server)
|
|
|
|
.get('/server-info')
|
|
|
|
.set('Authorization', `Bearer ${admin.accessToken}`);
|
2023-09-02 04:01:54 +02: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 () => {
|
|
|
|
const { status, body } = await request(server).get('/server-info/ping');
|
|
|
|
expect(status).toBe(200);
|
|
|
|
expect(body).toEqual({ res: 'pong' });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('GET /server-info/version', () => {
|
|
|
|
it('should respond with the server version', async () => {
|
|
|
|
const { status, body } = await request(server).get('/server-info/version');
|
|
|
|
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 () => {
|
|
|
|
const { status, body } = await request(server).get('/server-info/features');
|
|
|
|
expect(status).toBe(200);
|
|
|
|
expect(body).toEqual({
|
2023-10-06 23:32:28 +02:00
|
|
|
clipEncode: false,
|
2023-09-02 04:01:54 +02:00
|
|
|
configFile: false,
|
2023-10-06 23:32:28 +02:00
|
|
|
facialRecognition: false,
|
2023-09-09 04:51:46 +02:00
|
|
|
map: true,
|
2023-09-26 09:03:57 +02:00
|
|
|
reverseGeocoding: true,
|
2023-09-02 04:01:54 +02:00
|
|
|
oauth: false,
|
|
|
|
oauthAutoLaunch: false,
|
|
|
|
passwordLogin: true,
|
|
|
|
search: false,
|
|
|
|
sidecar: true,
|
2023-10-06 23:32:28 +02:00
|
|
|
tagImage: false,
|
2023-10-06 09:01:14 +02:00
|
|
|
trash: true,
|
2023-09-02 04:01:54 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-09-09 04:51:46 +02:00
|
|
|
describe('GET /server-info/config', () => {
|
|
|
|
it('should respond with the server configuration', async () => {
|
|
|
|
const { status, body } = await request(server).get('/server-info/config');
|
|
|
|
expect(status).toBe(200);
|
|
|
|
expect(body).toEqual({
|
|
|
|
loginPageMessage: '',
|
|
|
|
oauthButtonText: 'Login with OAuth',
|
2023-10-06 09:01:14 +02:00
|
|
|
trashDays: 30,
|
2023-10-11 04:37:13 +02:00
|
|
|
isInitialized: true,
|
2023-09-09 04:51:46 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-11-04 03:33:15 +02:00
|
|
|
describe('GET /server-info/statistics', () => {
|
2023-09-02 04:01:54 +02:00
|
|
|
it('should require authentication', async () => {
|
2023-11-04 03:33:15 +02:00
|
|
|
const { status, body } = await request(server).get('/server-info/statistics');
|
2023-09-02 04:01:54 +02:00
|
|
|
expect(status).toBe(401);
|
|
|
|
expect(body).toEqual(errorStub.unauthorized);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should only work for admins', async () => {
|
|
|
|
const { status, body } = await request(server)
|
2023-11-04 03:33:15 +02:00
|
|
|
.get('/server-info/statistics')
|
2023-11-15 03:08:22 +02:00
|
|
|
.set('Authorization', `Bearer ${nonAdmin.accessToken}`);
|
2023-09-02 04:01:54 +02:00
|
|
|
expect(status).toBe(403);
|
|
|
|
expect(body).toEqual(errorStub.forbidden);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return the server stats', async () => {
|
|
|
|
const { status, body } = await request(server)
|
2023-11-04 03:33:15 +02:00
|
|
|
.get('/server-info/statistics')
|
2023-11-15 03:08:22 +02:00
|
|
|
.set('Authorization', `Bearer ${admin.accessToken}`);
|
2023-09-02 04:01:54 +02:00
|
|
|
expect(status).toBe(200);
|
|
|
|
expect(body).toEqual({
|
|
|
|
photos: 0,
|
|
|
|
usage: 0,
|
|
|
|
usageByUser: [
|
|
|
|
{
|
|
|
|
photos: 0,
|
|
|
|
usage: 0,
|
2023-11-12 03:03:32 +02:00
|
|
|
userName: 'Immich Admin',
|
2023-11-15 03:08:22 +02:00
|
|
|
userId: admin.userId,
|
|
|
|
videos: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
photos: 0,
|
|
|
|
usage: 0,
|
|
|
|
userName: 'User 1',
|
|
|
|
userId: nonAdmin.userId,
|
2023-09-02 04:01:54 +02:00
|
|
|
videos: 0,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
videos: 0,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('GET /server-info/media-types', () => {
|
|
|
|
it('should return accepted media types', async () => {
|
|
|
|
const { status, body } = await request(server).get('/server-info/media-types');
|
|
|
|
expect(status).toBe(200);
|
|
|
|
expect(body).toEqual({
|
|
|
|
sidecar: ['.xmp'],
|
|
|
|
image: expect.any(Array),
|
|
|
|
video: expect.any(Array),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2023-10-26 00:13:05 +02:00
|
|
|
|
|
|
|
describe('GET /server-info/theme', () => {
|
|
|
|
it('should respond with the server theme', async () => {
|
|
|
|
const { status, body } = await request(server).get('/server-info/theme');
|
|
|
|
expect(status).toBe(200);
|
|
|
|
expect(body).toEqual({
|
2023-10-27 04:32:33 +02:00
|
|
|
customCss: '',
|
2023-10-26 00:13:05 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2023-09-02 04:01:54 +02:00
|
|
|
});
|