mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
52 lines
1.8 KiB
TypeScript
52 lines
1.8 KiB
TypeScript
import { mapAsset } from 'src/dtos/asset-response.dto';
|
|
import { ViewService } from 'src/services/view.service';
|
|
import { IViewRepository } from 'src/types';
|
|
import { assetStub } from 'test/fixtures/asset.stub';
|
|
import { authStub } from 'test/fixtures/auth.stub';
|
|
import { newTestService } from 'test/utils';
|
|
|
|
import { Mocked } from 'vitest';
|
|
|
|
describe(ViewService.name, () => {
|
|
let sut: ViewService;
|
|
let viewMock: Mocked<IViewRepository>;
|
|
|
|
beforeEach(() => {
|
|
({ sut, viewMock } = newTestService(ViewService));
|
|
});
|
|
|
|
it('should work', () => {
|
|
expect(sut).toBeDefined();
|
|
});
|
|
|
|
describe('getUniqueOriginalPaths', () => {
|
|
it('should return unique original paths', async () => {
|
|
const mockPaths = ['path1', 'path2', 'path3'];
|
|
viewMock.getUniqueOriginalPaths.mockResolvedValue(mockPaths);
|
|
|
|
const result = await sut.getUniqueOriginalPaths(authStub.admin);
|
|
|
|
expect(result).toEqual(mockPaths);
|
|
expect(viewMock.getUniqueOriginalPaths).toHaveBeenCalledWith(authStub.admin.user.id);
|
|
});
|
|
});
|
|
|
|
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 }));
|
|
|
|
viewMock.getAssetsByOriginalPath.mockResolvedValue(mockAssets as any);
|
|
|
|
const result = await sut.getAssetsByOriginalPath(authStub.admin, path);
|
|
expect(result).toEqual(mockAssetReponseDto);
|
|
await expect(viewMock.getAssetsByOriginalPath(authStub.admin.user.id, path)).resolves.toEqual(mockAssets);
|
|
});
|
|
});
|
|
});
|