refactor: timeline tests (#19641)

This commit is contained in:
Jason Rasmussen 2025-06-30 17:43:45 -04:00 committed by GitHub
parent 58ca1402ed
commit 93f9e118ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 200 additions and 230 deletions

View file

@ -0,0 +1,41 @@
import { TimelineController } from 'src/controllers/timeline.controller';
import { TimelineService } from 'src/services/timeline.service';
import request from 'supertest';
import { errorDto } from 'test/medium/responses';
import { ControllerContext, controllerSetup, mockBaseService } from 'test/utils';
describe(TimelineController.name, () => {
let ctx: ControllerContext;
const service = mockBaseService(TimelineService);
beforeAll(async () => {
ctx = await controllerSetup(TimelineController, [{ provide: TimelineService, useValue: service }]);
return () => ctx.close();
});
beforeEach(() => {
service.resetAllMocks();
ctx.reset();
});
describe('GET /timeline/buckets', () => {
it('should be an authenticated route', async () => {
await request(ctx.getHttpServer()).get('/timeline/buckets');
expect(ctx.authenticate).toHaveBeenCalled();
});
});
describe('GET /timeline/bucket', () => {
it('should be an authenticated route', async () => {
await request(ctx.getHttpServer()).get('/timeline/bucket?timeBucket=1900-01-01');
expect(ctx.authenticate).toHaveBeenCalled();
});
// TODO enable date string validation while still accepting 5 digit years
it.fails('should fail if time bucket is invalid', async () => {
const { status, body } = await request(ctx.getHttpServer()).get('/timeline/bucket').query({ timeBucket: 'foo' });
expect(status).toBe(400);
expect(body).toEqual(errorDto.badRequest('Invalid time bucket format'));
});
});
});