mirror of
https://github.com/immich-app/immich.git
synced 2025-04-21 23:38:34 +02:00
chore: finishing unit tests for a couple of services (#13292)
This commit is contained in:
parent
f5e0cdedbc
commit
9d0f03808c
17 changed files with 386 additions and 8 deletions
server
src/services
api-key.service.spec.tsasset.service.spec.tsauth.service.spec.tsdownload.service.spec.tsduplicate.service.spec.tsmap.service.spec.tsnotification.service.spec.tspartner.service.spec.tsshared-link.service.spec.tsshared-link.service.tssmart-info.service.spec.tsstorage.service.spec.tssystem-metadata.service.spec.tstag.service.spec.tstimeline.service.spec.tsversion.service.spec.ts
vitest.config.mjs
|
@ -46,6 +46,15 @@ describe(APIKeyService.name, () => {
|
|||
expect(cryptoMock.newPassword).toHaveBeenCalled();
|
||||
expect(cryptoMock.hashSha256).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should throw an error if the api key does not have sufficient permissions', async () => {
|
||||
await expect(
|
||||
sut.create(
|
||||
{ ...authStub.admin, apiKey: { ...keyStub.admin, permissions: [] } },
|
||||
{ permissions: [Permission.ASSET_READ] },
|
||||
),
|
||||
).rejects.toBeInstanceOf(BadRequestException);
|
||||
});
|
||||
});
|
||||
|
||||
describe('update', () => {
|
||||
|
|
|
@ -583,6 +583,12 @@ describe(AssetService.name, () => {
|
|||
});
|
||||
|
||||
describe('run', () => {
|
||||
it('should run the refresh faces job', async () => {
|
||||
accessMock.asset.checkOwnerAccess.mockResolvedValue(new Set(['asset-1']));
|
||||
await sut.run(authStub.admin, { assetIds: ['asset-1'], name: AssetJobName.REFRESH_FACES });
|
||||
expect(jobMock.queueAll).toHaveBeenCalledWith([{ name: JobName.FACE_DETECTION, data: { id: 'asset-1' } }]);
|
||||
});
|
||||
|
||||
it('should run the refresh metadata job', async () => {
|
||||
accessMock.asset.checkOwnerAccess.mockResolvedValue(new Set(['asset-1']));
|
||||
await sut.run(authStub.admin, { assetIds: ['asset-1'], name: AssetJobName.REFRESH_METADATA });
|
||||
|
|
|
@ -72,6 +72,13 @@ describe('AuthService', () => {
|
|||
expect(sut).toBeDefined();
|
||||
});
|
||||
|
||||
describe('onBootstrap', () => {
|
||||
it('should init the repo', () => {
|
||||
sut.onBootstrap();
|
||||
expect(oauthMock.init).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('login', () => {
|
||||
it('should throw an error if password login is disabled', async () => {
|
||||
systemMock.get.mockResolvedValue(systemConfigStub.disabled);
|
||||
|
|
|
@ -2,6 +2,7 @@ import { BadRequestException } from '@nestjs/common';
|
|||
import { DownloadResponseDto } from 'src/dtos/download.dto';
|
||||
import { AssetEntity } from 'src/entities/asset.entity';
|
||||
import { IAssetRepository } from 'src/interfaces/asset.interface';
|
||||
import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
||||
import { IStorageRepository } from 'src/interfaces/storage.interface';
|
||||
import { DownloadService } from 'src/services/download.service';
|
||||
import { assetStub } from 'test/fixtures/asset.stub';
|
||||
|
@ -25,6 +26,7 @@ describe(DownloadService.name, () => {
|
|||
let sut: DownloadService;
|
||||
let accessMock: IAccessRepositoryMock;
|
||||
let assetMock: Mocked<IAssetRepository>;
|
||||
let loggerMock: Mocked<ILoggerRepository>;
|
||||
let storageMock: Mocked<IStorageRepository>;
|
||||
|
||||
it('should work', () => {
|
||||
|
@ -32,10 +34,54 @@ describe(DownloadService.name, () => {
|
|||
});
|
||||
|
||||
beforeEach(() => {
|
||||
({ sut, accessMock, assetMock, storageMock } = newTestService(DownloadService));
|
||||
({ sut, accessMock, assetMock, loggerMock, storageMock } = newTestService(DownloadService));
|
||||
});
|
||||
|
||||
describe('downloadArchive', () => {
|
||||
it('should skip asset ids that could not be found', async () => {
|
||||
const archiveMock = {
|
||||
addFile: vitest.fn(),
|
||||
finalize: vitest.fn(),
|
||||
stream: new Readable(),
|
||||
};
|
||||
|
||||
accessMock.asset.checkOwnerAccess.mockResolvedValue(new Set(['asset-1', 'asset-2']));
|
||||
assetMock.getByIds.mockResolvedValue([{ ...assetStub.noResizePath, id: 'asset-1' }]);
|
||||
storageMock.createZipStream.mockReturnValue(archiveMock);
|
||||
|
||||
await expect(sut.downloadArchive(authStub.admin, { assetIds: ['asset-1', 'asset-2'] })).resolves.toEqual({
|
||||
stream: archiveMock.stream,
|
||||
});
|
||||
|
||||
expect(archiveMock.addFile).toHaveBeenCalledTimes(1);
|
||||
expect(archiveMock.addFile).toHaveBeenNthCalledWith(1, 'upload/library/IMG_123.jpg', 'IMG_123.jpg');
|
||||
});
|
||||
|
||||
it('should log a warning if the original path could not be resolved', async () => {
|
||||
const archiveMock = {
|
||||
addFile: vitest.fn(),
|
||||
finalize: vitest.fn(),
|
||||
stream: new Readable(),
|
||||
};
|
||||
|
||||
accessMock.asset.checkOwnerAccess.mockResolvedValue(new Set(['asset-1', 'asset-2']));
|
||||
storageMock.realpath.mockRejectedValue(new Error('Could not read file'));
|
||||
assetMock.getByIds.mockResolvedValue([
|
||||
{ ...assetStub.noResizePath, id: 'asset-1' },
|
||||
{ ...assetStub.noWebpPath, id: 'asset-2' },
|
||||
]);
|
||||
storageMock.createZipStream.mockReturnValue(archiveMock);
|
||||
|
||||
await expect(sut.downloadArchive(authStub.admin, { assetIds: ['asset-1', 'asset-2'] })).resolves.toEqual({
|
||||
stream: archiveMock.stream,
|
||||
});
|
||||
|
||||
expect(loggerMock.warn).toHaveBeenCalledTimes(2);
|
||||
expect(archiveMock.addFile).toHaveBeenCalledTimes(2);
|
||||
expect(archiveMock.addFile).toHaveBeenNthCalledWith(1, 'upload/library/IMG_123.jpg', 'IMG_123.jpg');
|
||||
expect(archiveMock.addFile).toHaveBeenNthCalledWith(2, 'upload/library/IMG_456.jpg', 'IMG_456.jpg');
|
||||
});
|
||||
|
||||
it('should download an archive', async () => {
|
||||
const archiveMock = {
|
||||
addFile: vitest.fn(),
|
||||
|
|
|
@ -6,6 +6,7 @@ import { ISystemMetadataRepository } from 'src/interfaces/system-metadata.interf
|
|||
import { DuplicateService } from 'src/services/duplicate.service';
|
||||
import { SearchService } from 'src/services/search.service';
|
||||
import { assetStub } from 'test/fixtures/asset.stub';
|
||||
import { authStub } from 'test/fixtures/auth.stub';
|
||||
import { newTestService } from 'test/utils';
|
||||
import { Mocked, beforeEach, vitest } from 'vitest';
|
||||
|
||||
|
@ -28,6 +29,15 @@ describe(SearchService.name, () => {
|
|||
expect(sut).toBeDefined();
|
||||
});
|
||||
|
||||
describe('getDuplicates', () => {
|
||||
it('should get duplicates', async () => {
|
||||
assetMock.getDuplicates.mockResolvedValue([assetStub.hasDupe]);
|
||||
await expect(sut.getDuplicates(authStub.admin)).resolves.toEqual([
|
||||
{ duplicateId: assetStub.hasDupe.duplicateId, assets: [expect.objectContaining({ id: assetStub.hasDupe.id })] },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('handleQueueSearchDuplicates', () => {
|
||||
beforeEach(() => {
|
||||
systemMock.get.mockResolvedValue({
|
||||
|
|
|
@ -1,19 +1,23 @@
|
|||
import { IAlbumRepository } from 'src/interfaces/album.interface';
|
||||
import { IMapRepository } from 'src/interfaces/map.interface';
|
||||
import { IPartnerRepository } from 'src/interfaces/partner.interface';
|
||||
import { MapService } from 'src/services/map.service';
|
||||
import { albumStub } from 'test/fixtures/album.stub';
|
||||
import { assetStub } from 'test/fixtures/asset.stub';
|
||||
import { authStub } from 'test/fixtures/auth.stub';
|
||||
import { partnerStub } from 'test/fixtures/partner.stub';
|
||||
import { newTestService } from 'test/utils';
|
||||
import { Mocked } from 'vitest';
|
||||
|
||||
describe(MapService.name, () => {
|
||||
let sut: MapService;
|
||||
|
||||
let albumMock: Mocked<IAlbumRepository>;
|
||||
let mapMock: Mocked<IMapRepository>;
|
||||
let partnerMock: Mocked<IPartnerRepository>;
|
||||
|
||||
beforeEach(() => {
|
||||
({ sut, mapMock, partnerMock } = newTestService(MapService));
|
||||
({ sut, albumMock, mapMock, partnerMock } = newTestService(MapService));
|
||||
});
|
||||
|
||||
describe('getMapMarkers', () => {
|
||||
|
@ -35,5 +39,62 @@ describe(MapService.name, () => {
|
|||
expect(markers).toHaveLength(1);
|
||||
expect(markers[0]).toEqual(marker);
|
||||
});
|
||||
|
||||
it('should include partner assets', async () => {
|
||||
const asset = assetStub.withLocation;
|
||||
const marker = {
|
||||
id: asset.id,
|
||||
lat: asset.exifInfo!.latitude!,
|
||||
lon: asset.exifInfo!.longitude!,
|
||||
city: asset.exifInfo!.city,
|
||||
state: asset.exifInfo!.state,
|
||||
country: asset.exifInfo!.country,
|
||||
};
|
||||
partnerMock.getAll.mockResolvedValue([partnerStub.adminToUser1]);
|
||||
mapMock.getMapMarkers.mockResolvedValue([marker]);
|
||||
|
||||
const markers = await sut.getMapMarkers(authStub.user1, { withPartners: true });
|
||||
|
||||
expect(mapMock.getMapMarkers).toHaveBeenCalledWith(
|
||||
[authStub.user1.user.id, partnerStub.adminToUser1.sharedById],
|
||||
expect.arrayContaining([]),
|
||||
{ withPartners: true },
|
||||
);
|
||||
expect(markers).toHaveLength(1);
|
||||
expect(markers[0]).toEqual(marker);
|
||||
});
|
||||
|
||||
it('should include assets from shared albums', async () => {
|
||||
const asset = assetStub.withLocation;
|
||||
const marker = {
|
||||
id: asset.id,
|
||||
lat: asset.exifInfo!.latitude!,
|
||||
lon: asset.exifInfo!.longitude!,
|
||||
city: asset.exifInfo!.city,
|
||||
state: asset.exifInfo!.state,
|
||||
country: asset.exifInfo!.country,
|
||||
};
|
||||
partnerMock.getAll.mockResolvedValue([]);
|
||||
mapMock.getMapMarkers.mockResolvedValue([marker]);
|
||||
albumMock.getOwned.mockResolvedValue([albumStub.empty]);
|
||||
albumMock.getShared.mockResolvedValue([albumStub.sharedWithUser]);
|
||||
|
||||
const markers = await sut.getMapMarkers(authStub.user1, { withSharedAlbums: true });
|
||||
|
||||
expect(markers).toHaveLength(1);
|
||||
expect(markers[0]).toEqual(marker);
|
||||
});
|
||||
});
|
||||
|
||||
describe('reverseGeocode', () => {
|
||||
it('should reverse geocode a location', async () => {
|
||||
mapMock.reverseGeocode.mockResolvedValue({ city: 'foo', state: 'bar', country: 'baz' });
|
||||
|
||||
await expect(sut.reverseGeocode({ lat: 42, lon: 69 })).resolves.toEqual([
|
||||
{ city: 'foo', state: 'bar', country: 'baz' },
|
||||
]);
|
||||
|
||||
expect(mapMock.reverseGeocode).toHaveBeenCalledWith({ latitude: 42, longitude: 69 });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -126,6 +126,14 @@ describe(NotificationService.name, () => {
|
|||
await expect(sut.onConfigValidate({ oldConfig, newConfig })).resolves.not.toThrow();
|
||||
expect(notificationMock.verifySmtp).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should fail if smtp configuration is invalid', async () => {
|
||||
const oldConfig = configs.smtpDisabled;
|
||||
const newConfig = configs.smtpEnabled;
|
||||
|
||||
notificationMock.verifySmtp.mockRejectedValue(new Error('Failed validating smtp'));
|
||||
await expect(sut.onConfigValidate({ oldConfig, newConfig })).rejects.toBeInstanceOf(Error);
|
||||
});
|
||||
});
|
||||
|
||||
describe('onAssetHide', () => {
|
||||
|
@ -180,6 +188,18 @@ describe(NotificationService.name, () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('onSessionDeleteEvent', () => {
|
||||
it('should send a on_session_delete client event', () => {
|
||||
vi.useFakeTimers();
|
||||
sut.onSessionDelete({ sessionId: 'id' });
|
||||
expect(eventMock.clientSend).not.toHaveBeenCalled();
|
||||
|
||||
vi.advanceTimersByTime(500);
|
||||
|
||||
expect(eventMock.clientSend).toHaveBeenCalledWith('on_session_delete', 'id', 'id');
|
||||
});
|
||||
});
|
||||
|
||||
describe('onAssetTrash', () => {
|
||||
it('should send connected clients an event', () => {
|
||||
sut.onAssetTrash({ assetId: 'asset-id', userId: 'user-id' });
|
||||
|
|
|
@ -3,15 +3,18 @@ import { IPartnerRepository, PartnerDirection } from 'src/interfaces/partner.int
|
|||
import { PartnerService } from 'src/services/partner.service';
|
||||
import { authStub } from 'test/fixtures/auth.stub';
|
||||
import { partnerStub } from 'test/fixtures/partner.stub';
|
||||
import { IAccessRepositoryMock } from 'test/repositories/access.repository.mock';
|
||||
import { newTestService } from 'test/utils';
|
||||
import { Mocked } from 'vitest';
|
||||
|
||||
describe(PartnerService.name, () => {
|
||||
let sut: PartnerService;
|
||||
|
||||
let accessMock: IAccessRepositoryMock;
|
||||
let partnerMock: Mocked<IPartnerRepository>;
|
||||
|
||||
beforeEach(() => {
|
||||
({ sut, partnerMock } = newTestService(PartnerService));
|
||||
({ sut, accessMock, partnerMock } = newTestService(PartnerService));
|
||||
});
|
||||
|
||||
it('should work', () => {
|
||||
|
@ -71,4 +74,24 @@ describe(PartnerService.name, () => {
|
|||
expect(partnerMock.remove).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('update', () => {
|
||||
it('should require access', async () => {
|
||||
await expect(sut.update(authStub.admin, 'shared-by-id', { inTimeline: false })).rejects.toBeInstanceOf(
|
||||
BadRequestException,
|
||||
);
|
||||
});
|
||||
|
||||
it('should update partner', async () => {
|
||||
accessMock.partner.checkUpdateAccess.mockResolvedValue(new Set(['shared-by-id']));
|
||||
partnerMock.update.mockResolvedValue(partnerStub.adminToUser1);
|
||||
|
||||
await expect(sut.update(authStub.admin, 'shared-by-id', { inTimeline: true })).resolves.toBeDefined();
|
||||
expect(partnerMock.update).toHaveBeenCalledWith({
|
||||
sharedById: 'shared-by-id',
|
||||
sharedWithId: authStub.admin.user.id,
|
||||
inTimeline: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -58,12 +58,21 @@ describe(SharedLinkService.name, () => {
|
|||
expect(sharedLinkMock.get).toHaveBeenCalledWith(authDto.user.id, authDto.sharedLink?.id);
|
||||
});
|
||||
|
||||
it('should throw an error for an password protected shared link', async () => {
|
||||
it('should throw an error for an invalid password protected shared link', async () => {
|
||||
const authDto = authStub.adminSharedLink;
|
||||
sharedLinkMock.get.mockResolvedValue(sharedLinkStub.passwordRequired);
|
||||
await expect(sut.getMine(authDto, {})).rejects.toBeInstanceOf(UnauthorizedException);
|
||||
expect(sharedLinkMock.get).toHaveBeenCalledWith(authDto.user.id, authDto.sharedLink?.id);
|
||||
});
|
||||
|
||||
it('should allow a correct password on a password protected shared link', async () => {
|
||||
sharedLinkMock.get.mockResolvedValue({ ...sharedLinkStub.individual, password: '123' });
|
||||
await expect(sut.getMine(authStub.adminSharedLink, { password: '123' })).resolves.toBeDefined();
|
||||
expect(sharedLinkMock.get).toHaveBeenCalledWith(
|
||||
authStub.adminSharedLink.user.id,
|
||||
authStub.adminSharedLink.sharedLink?.id,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('get', () => {
|
||||
|
@ -300,5 +309,15 @@ describe(SharedLinkService.name, () => {
|
|||
});
|
||||
expect(sharedLinkMock.get).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should return metadata tags with a default image path if the asset id is not set', async () => {
|
||||
sharedLinkMock.get.mockResolvedValue({ ...sharedLinkStub.individual, album: undefined, assets: [] });
|
||||
await expect(sut.getMetadataTags(authStub.adminSharedLink)).resolves.toEqual({
|
||||
description: '0 shared photos & videos',
|
||||
imageUrl: `${DEFAULT_EXTERNAL_DOMAIN}/feature-panel.png`,
|
||||
title: 'Public Share',
|
||||
});
|
||||
expect(sharedLinkMock.get).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -20,7 +20,7 @@ import { OpenGraphTags } from 'src/utils/misc';
|
|||
|
||||
@Injectable()
|
||||
export class SharedLinkService extends BaseService {
|
||||
getAll(auth: AuthDto): Promise<SharedLinkResponseDto[]> {
|
||||
async getAll(auth: AuthDto): Promise<SharedLinkResponseDto[]> {
|
||||
return this.sharedLinkRepository.getAll(auth.user.id).then((links) => links.map((link) => mapSharedLink(link)));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { SystemConfig } from 'src/config';
|
||||
import { ImmichWorker } from 'src/enum';
|
||||
import { IAssetRepository, WithoutProperty } from 'src/interfaces/asset.interface';
|
||||
import { IDatabaseRepository } from 'src/interfaces/database.interface';
|
||||
import { IJobRepository, JobName, JobStatus } from 'src/interfaces/job.interface';
|
||||
import { IMachineLearningRepository } from 'src/interfaces/machine-learning.interface';
|
||||
import { ISearchRepository } from 'src/interfaces/search.interface';
|
||||
|
@ -16,13 +17,15 @@ describe(SmartInfoService.name, () => {
|
|||
let sut: SmartInfoService;
|
||||
|
||||
let assetMock: Mocked<IAssetRepository>;
|
||||
let databaseMock: Mocked<IDatabaseRepository>;
|
||||
let jobMock: Mocked<IJobRepository>;
|
||||
let machineLearningMock: Mocked<IMachineLearningRepository>;
|
||||
let searchMock: Mocked<ISearchRepository>;
|
||||
let systemMock: Mocked<ISystemMetadataRepository>;
|
||||
|
||||
beforeEach(() => {
|
||||
({ sut, assetMock, jobMock, machineLearningMock, searchMock, systemMock } = newTestService(SmartInfoService));
|
||||
({ sut, assetMock, databaseMock, jobMock, machineLearningMock, searchMock, systemMock } =
|
||||
newTestService(SmartInfoService));
|
||||
|
||||
assetMock.getByIds.mockResolvedValue([assetStub.image]);
|
||||
});
|
||||
|
@ -317,6 +320,30 @@ describe(SmartInfoService.name, () => {
|
|||
expect(machineLearningMock.encodeImage).not.toHaveBeenCalled();
|
||||
expect(searchMock.upsert).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should fail if asset could not be found', async () => {
|
||||
assetMock.getByIds.mockResolvedValue([]);
|
||||
|
||||
expect(await sut.handleEncodeClip({ id: assetStub.image.id })).toEqual(JobStatus.FAILED);
|
||||
|
||||
expect(machineLearningMock.encodeImage).not.toHaveBeenCalled();
|
||||
expect(searchMock.upsert).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should wait for database', async () => {
|
||||
machineLearningMock.encodeImage.mockResolvedValue([0.01, 0.02, 0.03]);
|
||||
databaseMock.isBusy.mockReturnValue(true);
|
||||
|
||||
expect(await sut.handleEncodeClip({ id: assetStub.image.id })).toEqual(JobStatus.SUCCESS);
|
||||
|
||||
expect(databaseMock.wait).toHaveBeenCalledWith(512);
|
||||
expect(machineLearningMock.encodeImage).toHaveBeenCalledWith(
|
||||
'http://immich-machine-learning:3003',
|
||||
'/uploads/user-id/thumbs/path.jpg',
|
||||
expect.objectContaining({ modelName: 'ViT-B-32__openai' }),
|
||||
);
|
||||
expect(searchMock.upsert).toHaveBeenCalledWith(assetStub.image.id, [0.01, 0.02, 0.03]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getCLIPModelInfo', () => {
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import { SystemMetadataKey } from 'src/enum';
|
||||
import { IConfigRepository } from 'src/interfaces/config.interface';
|
||||
import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
||||
import { IStorageRepository } from 'src/interfaces/storage.interface';
|
||||
import { ISystemMetadataRepository } from 'src/interfaces/system-metadata.interface';
|
||||
import { StorageService } from 'src/services/storage.service';
|
||||
import { ImmichStartupError, StorageService } from 'src/services/storage.service';
|
||||
import { mockEnvData } from 'test/repositories/config.repository.mock';
|
||||
import { newTestService } from 'test/utils';
|
||||
import { Mocked } from 'vitest';
|
||||
|
@ -11,11 +12,12 @@ describe(StorageService.name, () => {
|
|||
let sut: StorageService;
|
||||
|
||||
let configMock: Mocked<IConfigRepository>;
|
||||
let loggerMock: Mocked<ILoggerRepository>;
|
||||
let storageMock: Mocked<IStorageRepository>;
|
||||
let systemMock: Mocked<ISystemMetadataRepository>;
|
||||
|
||||
beforeEach(() => {
|
||||
({ sut, configMock, storageMock, systemMock } = newTestService(StorageService));
|
||||
({ sut, configMock, loggerMock, storageMock, systemMock } = newTestService(StorageService));
|
||||
});
|
||||
|
||||
it('should work', () => {
|
||||
|
@ -59,6 +61,25 @@ describe(StorageService.name, () => {
|
|||
expect(systemMock.set).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should skip mount file creation if file already exists', async () => {
|
||||
const error = new Error('Error creating file') as any;
|
||||
error.code = 'EEXIST';
|
||||
systemMock.get.mockResolvedValue({ mountFiles: false });
|
||||
storageMock.createFile.mockRejectedValue(error);
|
||||
|
||||
await expect(sut.onBootstrap()).resolves.toBeUndefined();
|
||||
|
||||
expect(loggerMock.warn).toHaveBeenCalledWith('Found existing mount file, skipping creation');
|
||||
});
|
||||
|
||||
it('should throw an error if mount file could not be created', async () => {
|
||||
systemMock.get.mockResolvedValue({ mountFiles: false });
|
||||
storageMock.createFile.mockRejectedValue(new Error('Error creating file'));
|
||||
|
||||
await expect(sut.onBootstrap()).rejects.toBeInstanceOf(ImmichStartupError);
|
||||
expect(systemMock.set).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should startup if checks are disabled', async () => {
|
||||
systemMock.get.mockResolvedValue({ mountFiles: true });
|
||||
configMock.getEnv.mockReturnValue(
|
||||
|
|
|
@ -16,6 +16,19 @@ describe(SystemMetadataService.name, () => {
|
|||
expect(sut).toBeDefined();
|
||||
});
|
||||
|
||||
describe('getAdminOnboarding', () => {
|
||||
it('should get isOnboarded state', async () => {
|
||||
systemMock.get.mockResolvedValue({ isOnboarded: true });
|
||||
await expect(sut.getAdminOnboarding()).resolves.toEqual({ isOnboarded: true });
|
||||
expect(systemMock.get).toHaveBeenCalledWith('admin-onboarding');
|
||||
});
|
||||
|
||||
it('should default isOnboarded to false', async () => {
|
||||
await expect(sut.getAdminOnboarding()).resolves.toEqual({ isOnboarded: false });
|
||||
expect(systemMock.get).toHaveBeenCalledWith('admin-onboarding');
|
||||
});
|
||||
});
|
||||
|
||||
describe('updateAdminOnboarding', () => {
|
||||
it('should update isOnboarded to true', async () => {
|
||||
await expect(sut.updateAdminOnboarding({ isOnboarded: true })).resolves.toBeUndefined();
|
||||
|
@ -27,4 +40,21 @@ describe(SystemMetadataService.name, () => {
|
|||
expect(systemMock.set).toHaveBeenCalledWith(SystemMetadataKey.ADMIN_ONBOARDING, { isOnboarded: false });
|
||||
});
|
||||
});
|
||||
|
||||
describe('getReverseGeocodingState', () => {
|
||||
it('should get reverse geocoding state', async () => {
|
||||
systemMock.get.mockResolvedValue({ lastUpdate: '2024-01-01', lastImportFileName: 'foo.bar' });
|
||||
await expect(sut.getReverseGeocodingState()).resolves.toEqual({
|
||||
lastUpdate: '2024-01-01',
|
||||
lastImportFileName: 'foo.bar',
|
||||
});
|
||||
});
|
||||
|
||||
it('should default reverse geocoding state to null', async () => {
|
||||
await expect(sut.getReverseGeocodingState()).resolves.toEqual({
|
||||
lastUpdate: null,
|
||||
lastImportFileName: null,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { BadRequestException } from '@nestjs/common';
|
||||
import { BulkIdErrorReason } from 'src/dtos/asset-ids.response.dto';
|
||||
import { JobStatus } from 'src/interfaces/job.interface';
|
||||
import { ITagRepository } from 'src/interfaces/tag.interface';
|
||||
import { TagService } from 'src/services/tag.service';
|
||||
import { authStub } from 'test/fixtures/auth.stub';
|
||||
|
@ -261,4 +262,11 @@ describe(TagService.name, () => {
|
|||
expect(tagMock.removeAssetIds).toHaveBeenCalledWith('tag-1', ['asset-1']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('handleTagCleanup', () => {
|
||||
it('should delete empty tags', async () => {
|
||||
await expect(sut.handleTagCleanup()).resolves.toBe(JobStatus.SUCCESS);
|
||||
expect(tagMock.deleteEmptyTags).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -69,6 +69,70 @@ describe(TimelineService.name, () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('should include partner shared assets', async () => {
|
||||
assetMock.getTimeBucket.mockResolvedValue([assetStub.image]);
|
||||
|
||||
await expect(
|
||||
sut.getTimeBucket(authStub.admin, {
|
||||
size: TimeBucketSize.DAY,
|
||||
timeBucket: 'bucket',
|
||||
isArchived: false,
|
||||
userId: authStub.admin.user.id,
|
||||
withPartners: true,
|
||||
}),
|
||||
).resolves.toEqual(expect.arrayContaining([expect.objectContaining({ id: 'asset-id' })]));
|
||||
expect(assetMock.getTimeBucket).toHaveBeenCalledWith('bucket', {
|
||||
size: TimeBucketSize.DAY,
|
||||
timeBucket: 'bucket',
|
||||
isArchived: false,
|
||||
withPartners: true,
|
||||
userIds: [authStub.admin.user.id],
|
||||
});
|
||||
});
|
||||
|
||||
it('should check permissions to read tag', async () => {
|
||||
assetMock.getTimeBucket.mockResolvedValue([assetStub.image]);
|
||||
accessMock.tag.checkOwnerAccess.mockResolvedValue(new Set(['tag-123']));
|
||||
|
||||
await expect(
|
||||
sut.getTimeBucket(authStub.admin, {
|
||||
size: TimeBucketSize.DAY,
|
||||
timeBucket: 'bucket',
|
||||
userId: authStub.admin.user.id,
|
||||
tagId: 'tag-123',
|
||||
}),
|
||||
).resolves.toEqual(expect.arrayContaining([expect.objectContaining({ id: 'asset-id' })]));
|
||||
expect(assetMock.getTimeBucket).toHaveBeenCalledWith('bucket', {
|
||||
size: TimeBucketSize.DAY,
|
||||
tagId: 'tag-123',
|
||||
timeBucket: 'bucket',
|
||||
userIds: [authStub.admin.user.id],
|
||||
});
|
||||
});
|
||||
|
||||
it('should strip metadata if showExif is disabled', async () => {
|
||||
accessMock.album.checkSharedLinkAccess.mockResolvedValue(new Set(['album-id']));
|
||||
assetMock.getTimeBucket.mockResolvedValue([assetStub.image]);
|
||||
|
||||
const buckets = await sut.getTimeBucket(
|
||||
{ ...authStub.admin, sharedLink: { ...authStub.adminSharedLink.sharedLink!, showExif: false } },
|
||||
{
|
||||
size: TimeBucketSize.DAY,
|
||||
timeBucket: 'bucket',
|
||||
isArchived: true,
|
||||
albumId: 'album-id',
|
||||
},
|
||||
);
|
||||
expect(buckets).toEqual([expect.objectContaining({ id: 'asset-id' })]);
|
||||
expect(buckets[0]).not.toHaveProperty('exif');
|
||||
expect(assetMock.getTimeBucket).toHaveBeenCalledWith('bucket', {
|
||||
size: TimeBucketSize.DAY,
|
||||
timeBucket: 'bucket',
|
||||
isArchived: true,
|
||||
albumId: 'album-id',
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the assets for a library time bucket if user has library.read', async () => {
|
||||
assetMock.getTimeBucket.mockResolvedValue([assetStub.image]);
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { DateTime } from 'luxon';
|
||||
import { SemVer } from 'semver';
|
||||
import { serverVersion } from 'src/constants';
|
||||
import { ImmichEnvironment, SystemMetadataKey } from 'src/enum';
|
||||
import { IConfigRepository } from 'src/interfaces/config.interface';
|
||||
|
@ -103,6 +104,11 @@ describe(VersionService.name, () => {
|
|||
await expect(sut.handleVersionCheck()).resolves.toEqual(JobStatus.SKIPPED);
|
||||
});
|
||||
|
||||
it('should not run if version check is disabled', async () => {
|
||||
systemMock.get.mockResolvedValue({ newVersionCheck: { enabled: false } });
|
||||
await expect(sut.handleVersionCheck()).resolves.toEqual(JobStatus.SKIPPED);
|
||||
});
|
||||
|
||||
it('should run if it has been > 60 minutes', async () => {
|
||||
serverInfoMock.getGitHubRelease.mockResolvedValue(mockRelease('v100.0.0'));
|
||||
systemMock.get.mockResolvedValue({
|
||||
|
@ -133,4 +139,19 @@ describe(VersionService.name, () => {
|
|||
expect(loggerMock.warn).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('onWebsocketConnectionEvent', () => {
|
||||
it('should send on_server_version client event', async () => {
|
||||
await sut.onWebsocketConnection({ userId: '42' });
|
||||
expect(eventMock.clientSend).toHaveBeenCalledWith('on_server_version', '42', expect.any(SemVer));
|
||||
expect(eventMock.clientSend).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should also send a new release notification', async () => {
|
||||
systemMock.get.mockResolvedValue({ checkedAt: '2024-01-01', releaseVersion: 'v1.42.0' });
|
||||
await sut.onWebsocketConnection({ userId: '42' });
|
||||
expect(eventMock.clientSend).toHaveBeenCalledWith('on_server_version', '42', expect.any(SemVer));
|
||||
expect(eventMock.clientSend).toHaveBeenCalledWith('on_new_release', '42', expect.any(Object));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -9,6 +9,12 @@ export default defineConfig({
|
|||
coverage: {
|
||||
provider: 'v8',
|
||||
include: ['src/cores/**', 'src/interfaces/**', 'src/services/**', 'src/utils/**'],
|
||||
exclude: [
|
||||
'src/services/*.spec.ts',
|
||||
'src/services/api.service.ts',
|
||||
'src/services/microservices.service.ts',
|
||||
'src/services/index.ts',
|
||||
],
|
||||
thresholds: {
|
||||
lines: 80,
|
||||
statements: 80,
|
||||
|
|
Loading…
Add table
Reference in a new issue