refactor(server): job handlers (#2572)
* refactor(server): job handlers * chore: remove comment * chore: add comments for
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
import { AssetEntity, AssetType } from '@app/infra/entities';
|
||||
import { assetEntityStub, authStub, newAssetRepositoryMock, newJobRepositoryMock } from '../../test';
|
||||
import { assetEntityStub, authStub, newAssetRepositoryMock } from '../../test';
|
||||
import { AssetService, IAssetRepository } from '../asset';
|
||||
import { IJobRepository, JobName } from '../job';
|
||||
|
||||
describe(AssetService.name, () => {
|
||||
let sut: AssetService;
|
||||
let assetMock: jest.Mocked<IAssetRepository>;
|
||||
let jobMock: jest.Mocked<IJobRepository>;
|
||||
|
||||
it('should work', () => {
|
||||
expect(sut).toBeDefined();
|
||||
@@ -14,49 +11,7 @@ describe(AssetService.name, () => {
|
||||
|
||||
beforeEach(async () => {
|
||||
assetMock = newAssetRepositoryMock();
|
||||
jobMock = newJobRepositoryMock();
|
||||
sut = new AssetService(assetMock, jobMock);
|
||||
});
|
||||
|
||||
describe(`handle asset upload`, () => {
|
||||
it('should process an uploaded video', async () => {
|
||||
const data = { asset: { type: AssetType.VIDEO } as AssetEntity };
|
||||
|
||||
await expect(sut.handleAssetUpload(data)).resolves.toBeUndefined();
|
||||
|
||||
expect(jobMock.queue).toHaveBeenCalledTimes(3);
|
||||
expect(jobMock.queue.mock.calls).toEqual([
|
||||
[{ name: JobName.GENERATE_JPEG_THUMBNAIL, data }],
|
||||
[{ name: JobName.VIDEO_CONVERSION, data }],
|
||||
[{ name: JobName.EXTRACT_VIDEO_METADATA, data }],
|
||||
]);
|
||||
});
|
||||
|
||||
it('should process an uploaded image', async () => {
|
||||
const data = { asset: { type: AssetType.IMAGE } as AssetEntity };
|
||||
|
||||
await sut.handleAssetUpload(data);
|
||||
|
||||
expect(jobMock.queue).toHaveBeenCalledTimes(2);
|
||||
expect(jobMock.queue.mock.calls).toEqual([
|
||||
[{ name: JobName.GENERATE_JPEG_THUMBNAIL, data }],
|
||||
[{ name: JobName.EXIF_EXTRACTION, data }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('save', () => {
|
||||
it('should save an asset', async () => {
|
||||
assetMock.save.mockResolvedValue(assetEntityStub.image);
|
||||
|
||||
await sut.save(assetEntityStub.image);
|
||||
|
||||
expect(assetMock.save).toHaveBeenCalledWith(assetEntityStub.image);
|
||||
expect(jobMock.queue).toHaveBeenCalledWith({
|
||||
name: JobName.SEARCH_INDEX_ASSET,
|
||||
data: { ids: [assetEntityStub.image.id] },
|
||||
});
|
||||
});
|
||||
sut = new AssetService(assetMock);
|
||||
});
|
||||
|
||||
describe('get map markers', () => {
|
||||
|
||||
Reference in New Issue
Block a user