2024-08-21 19:49:37 +01:00
|
|
|
import { mapAsset } from 'src/dtos/asset-response.dto';
|
2024-09-17 16:32:09 -04:00
|
|
|
import { IViewRepository } from 'src/interfaces/view.interface';
|
2024-08-21 19:49:37 +01:00
|
|
|
import { ViewService } from 'src/services/view.service';
|
|
|
|
|
import { assetStub } from 'test/fixtures/asset.stub';
|
|
|
|
|
import { authStub } from 'test/fixtures/auth.stub';
|
2024-09-17 16:32:09 -04:00
|
|
|
import { newViewRepositoryMock } from 'test/repositories/view.repository.mock';
|
2024-08-21 19:49:37 +01:00
|
|
|
|
|
|
|
|
import { Mocked } from 'vitest';
|
|
|
|
|
|
|
|
|
|
describe(ViewService.name, () => {
|
|
|
|
|
let sut: ViewService;
|
2024-09-17 16:32:09 -04:00
|
|
|
let viewMock: Mocked<IViewRepository>;
|
2024-08-21 19:49:37 +01:00
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2024-09-17 16:32:09 -04:00
|
|
|
viewMock = newViewRepositoryMock();
|
2024-08-21 19:49:37 +01:00
|
|
|
|
2024-09-17 16:32:09 -04:00
|
|
|
sut = new ViewService(viewMock);
|
2024-08-21 19:49:37 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should work', () => {
|
|
|
|
|
expect(sut).toBeDefined();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('getUniqueOriginalPaths', () => {
|
|
|
|
|
it('should return unique original paths', async () => {
|
|
|
|
|
const mockPaths = ['path1', 'path2', 'path3'];
|
2024-09-17 16:32:09 -04:00
|
|
|
viewMock.getUniqueOriginalPaths.mockResolvedValue(mockPaths);
|
2024-08-21 19:49:37 +01:00
|
|
|
|
|
|
|
|
const result = await sut.getUniqueOriginalPaths(authStub.admin);
|
|
|
|
|
|
|
|
|
|
expect(result).toEqual(mockPaths);
|
2024-09-17 16:32:09 -04:00
|
|
|
expect(viewMock.getUniqueOriginalPaths).toHaveBeenCalledWith(authStub.admin.user.id);
|
2024-08-21 19:49:37 +01:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('getAssetsByOriginalPath', () => {
|
|
|
|
|
it('should return assets by original path', async () => {
|
|
|
|
|
const path = '/asset';
|
|
|
|
|
|
|
|
|
|
const asset1 = { ...assetStub.image, originalPath: '/asset/path1' };
|
|
|
|
|
const asset2 = { ...assetStub.image, originalPath: '/asset/path2' };
|
|
|
|
|
|
|
|
|
|
const mockAssets = [asset1, asset2];
|
|
|
|
|
|
|
|
|
|
const mockAssetReponseDto = mockAssets.map((a) => mapAsset(a, { auth: authStub.admin }));
|
|
|
|
|
|
2024-09-17 16:32:09 -04:00
|
|
|
viewMock.getAssetsByOriginalPath.mockResolvedValue(mockAssets);
|
2024-08-21 19:49:37 +01:00
|
|
|
|
|
|
|
|
const result = await sut.getAssetsByOriginalPath(authStub.admin, path);
|
|
|
|
|
expect(result).toEqual(mockAssetReponseDto);
|
2024-09-17 16:32:09 -04:00
|
|
|
await expect(viewMock.getAssetsByOriginalPath(authStub.admin.user.id, path)).resolves.toEqual(mockAssets);
|
2024-08-21 19:49:37 +01:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|