mirror of
https://github.com/immich-app/immich.git
synced 2025-12-23 17:25:11 +03:00
refactor: controller tests (#18100)
This commit is contained in:
46
server/src/controllers/download.controller.spec.ts
Normal file
46
server/src/controllers/download.controller.spec.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { DownloadController } from 'src/controllers/download.controller';
|
||||
import { DownloadService } from 'src/services/download.service';
|
||||
import request from 'supertest';
|
||||
import { factory } from 'test/small.factory';
|
||||
import { ControllerContext, controllerSetup, mockBaseService } from 'test/utils';
|
||||
import { Readable } from 'typeorm/platform/PlatformTools.js';
|
||||
|
||||
describe(DownloadController.name, () => {
|
||||
let ctx: ControllerContext;
|
||||
const service = mockBaseService(DownloadService);
|
||||
|
||||
beforeAll(async () => {
|
||||
ctx = await controllerSetup(DownloadController, [{ provide: DownloadService, useValue: service }]);
|
||||
return () => ctx.close();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
service.resetAllMocks();
|
||||
ctx.reset();
|
||||
});
|
||||
|
||||
describe('POST /download/info', () => {
|
||||
it('should be an authenticated route', async () => {
|
||||
await request(ctx.getHttpServer())
|
||||
.post('/download/info')
|
||||
.send({ assetIds: [factory.uuid()] });
|
||||
expect(ctx.authenticate).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /download/archive', () => {
|
||||
it('should be an authenticated route', async () => {
|
||||
const stream = new Readable({
|
||||
read() {
|
||||
this.push('test');
|
||||
this.push(null);
|
||||
},
|
||||
});
|
||||
service.downloadArchive.mockResolvedValue({ stream });
|
||||
await request(ctx.getHttpServer())
|
||||
.post('/download/archive')
|
||||
.send({ assetIds: [factory.uuid()] });
|
||||
expect(ctx.authenticate).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user