2024-05-29 17:51:01 +02:00
|
|
|
import { LoginResponseDto, getConfig } from '@immich/sdk';
|
2024-02-19 22:34:18 -05:00
|
|
|
import { errorDto } from 'src/responses';
|
2024-03-21 23:59:21 +01:00
|
|
|
import { app, asBearerAuth, utils } from 'src/utils';
|
2023-11-09 20:23:03 -05:00
|
|
|
import request from 'supertest';
|
2024-02-19 22:34:18 -05:00
|
|
|
import { beforeAll, describe, expect, it } from 'vitest';
|
2023-11-09 20:23:03 -05:00
|
|
|
|
2024-03-21 23:59:21 +01:00
|
|
|
const getSystemConfig = (accessToken: string) => getConfig({ headers: asBearerAuth(accessToken) });
|
|
|
|
|
|
2024-02-19 22:34:18 -05:00
|
|
|
describe('/system-config', () => {
|
2023-11-09 20:23:03 -05:00
|
|
|
let admin: LoginResponseDto;
|
|
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
2024-03-07 10:14:36 -05:00
|
|
|
await utils.resetDatabase();
|
|
|
|
|
admin = await utils.adminSetup();
|
2023-11-09 20:23:03 -05:00
|
|
|
});
|
2024-03-21 23:59:21 +01:00
|
|
|
|
|
|
|
|
describe('PUT /system-config', () => {
|
|
|
|
|
it('should require authentication', async () => {
|
|
|
|
|
const { status, body } = await request(app).put('/system-config');
|
|
|
|
|
expect(status).toBe(401);
|
|
|
|
|
expect(body).toEqual(errorDto.unauthorized);
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-13 12:29:39 -04:00
|
|
|
it('should always return the new config', async () => {
|
|
|
|
|
const config = await getSystemConfig(admin.accessToken);
|
|
|
|
|
|
|
|
|
|
const response1 = await request(app)
|
|
|
|
|
.put('/system-config')
|
|
|
|
|
.set('Authorization', `Bearer ${admin.accessToken}`)
|
|
|
|
|
.send({ ...config, newVersionCheck: { enabled: false } });
|
|
|
|
|
|
|
|
|
|
expect(response1.status).toBe(200);
|
|
|
|
|
expect(response1.body).toEqual({ ...config, newVersionCheck: { enabled: false } });
|
|
|
|
|
|
|
|
|
|
const response2 = await request(app)
|
|
|
|
|
.put('/system-config')
|
|
|
|
|
.set('Authorization', `Bearer ${admin.accessToken}`)
|
|
|
|
|
.send({ ...config, newVersionCheck: { enabled: true } });
|
|
|
|
|
|
|
|
|
|
expect(response2.status).toBe(200);
|
|
|
|
|
expect(response2.body).toEqual({ ...config, newVersionCheck: { enabled: true } });
|
|
|
|
|
});
|
|
|
|
|
|
2024-03-21 23:59:21 +01:00
|
|
|
it('should reject an invalid config entry', async () => {
|
|
|
|
|
const { status, body } = await request(app)
|
|
|
|
|
.put('/system-config')
|
|
|
|
|
.set('Authorization', `Bearer ${admin.accessToken}`)
|
|
|
|
|
.send({
|
|
|
|
|
...(await getSystemConfig(admin.accessToken)),
|
|
|
|
|
storageTemplate: { enabled: true, hashVerificationEnabled: true, template: '{{foo}}' },
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(status).toBe(400);
|
|
|
|
|
expect(body).toEqual(errorDto.badRequest(expect.stringContaining('Invalid storage template')));
|
|
|
|
|
});
|
|
|
|
|
});
|
2023-11-09 20:23:03 -05:00
|
|
|
});
|