immich/server/src/controllers/app.controller.spec.ts
Jason Rasmussen ea9f11bf39
refactor: controller tests (#18035)
* feat: controller unit tests

* refactor: controller tests
2025-05-03 09:39:44 -04:00

50 lines
1.6 KiB
TypeScript

import { AppController } from 'src/controllers/app.controller';
import { SystemConfigService } from 'src/services/system-config.service';
import request from 'supertest';
import { ControllerContext, controllerSetup, mockBaseService } from 'test/utils';
describe(AppController.name, () => {
let ctx: ControllerContext;
beforeAll(async () => {
ctx = await controllerSetup(AppController, [
{ provide: SystemConfigService, useValue: mockBaseService(SystemConfigService) },
]);
return () => ctx.close();
});
beforeEach(() => {
ctx.reset();
});
describe('GET /.well-known/immich', () => {
it('should not be an authenticated route', async () => {
await request(ctx.getHttpServer()).post('/.well-known/immich');
expect(ctx.authenticate).not.toHaveBeenCalled();
});
it('should return a 200 status code', async () => {
const { status, body } = await request(ctx.getHttpServer()).get('/.well-known/immich');
expect(status).toBe(200);
expect(body).toEqual({
api: {
endpoint: '/api',
},
});
});
});
describe('GET /custom.css', () => {
it('should not be an authenticated route', async () => {
await request(ctx.getHttpServer()).post('/custom.css');
expect(ctx.authenticate).not.toHaveBeenCalled();
});
it('should reply with text/css', async () => {
const { status, headers } = await request(ctx.getHttpServer()).get('/custom.css');
expect(status).toBe(200);
expect(headers['content-type']).toEqual('text/css; charset=utf-8');
});
});
});