From 75c065c83ab620e63f84a7a10ded0521f5258ba6 Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Thu, 9 Nov 2023 20:23:03 -0500 Subject: [PATCH] chore(server): e2e test (#4941) --- server/test/e2e/system-config.e2e-spec.ts | 79 +++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 server/test/e2e/system-config.e2e-spec.ts diff --git a/server/test/e2e/system-config.e2e-spec.ts b/server/test/e2e/system-config.e2e-spec.ts new file mode 100644 index 0000000000..dd7a69439c --- /dev/null +++ b/server/test/e2e/system-config.e2e-spec.ts @@ -0,0 +1,79 @@ +import { LoginResponseDto } from '@app/domain'; +import { SystemConfigController } from '@app/immich'; +import { api } from '@test/api'; +import { db } from '@test/db'; +import { errorStub } from '@test/fixtures'; +import { testApp } from '@test/test-utils'; +import request from 'supertest'; + +describe(`${SystemConfigController.name} (e2e)`, () => { + let server: any; + let admin: LoginResponseDto; + + beforeAll(async () => { + [server] = await testApp.create(); + }); + + afterAll(async () => { + await testApp.teardown(); + }); + + beforeEach(async () => { + await db.reset(); + await api.authApi.adminSignUp(server); + admin = await api.authApi.adminLogin(server); + }); + + describe('GET /system-config/map/style.json', () => { + it('should require authentication', async () => { + const { status, body } = await request(server).get('/system-config/map/style.json'); + expect(status).toBe(401); + expect(body).toEqual(errorStub.unauthorized); + }); + + it('should throw an error if a theme is not light or dark', async () => { + for (const theme of ['dark1', true, 123, '', null, undefined]) { + const { status, body } = await request(server) + .get('/system-config/map/style.json') + .query({ theme }) + .set('Authorization', `Bearer ${admin.accessToken}`); + expect(status).toBe(400); + expect(body).toEqual(errorStub.badRequest(['theme must be one of the following values: light, dark'])); + } + }); + + it('should return the light style.json', async () => { + const { status, body } = await request(server) + .get('/system-config/map/style.json') + .query({ theme: 'light' }) + .set('Authorization', `Bearer ${admin.accessToken}`); + expect(status).toBe(200); + expect(body).toEqual(expect.objectContaining({ id: 'immich-map-light' })); + }); + + it('should return the dark style.json', async () => { + const { status, body } = await request(server) + .get('/system-config/map/style.json') + .query({ theme: 'dark' }) + .set('Authorization', `Bearer ${admin.accessToken}`); + expect(status).toBe(200); + expect(body).toEqual(expect.objectContaining({ id: 'immich-map-dark' })); + }); + + it('should not require admin authentication', async () => { + const credentials = { email: 'user1@immich.app', password: 'Password123' }; + await api.userApi.create(server, admin.accessToken, { + ...credentials, + firstName: 'User 1', + lastName: 'Test', + }); + const { accessToken } = await api.authApi.login(server, credentials); + const { status, body } = await request(server) + .get('/system-config/map/style.json') + .query({ theme: 'dark' }) + .set('Authorization', `Bearer ${accessToken}`); + expect(status).toBe(200); + expect(body).toEqual(expect.objectContaining({ id: 'immich-map-dark' })); + }); + }); +});