mirror of
https://github.com/immich-app/immich.git
synced 2026-03-25 19:18:57 +03:00
refactor: config init event for first config load (#13930)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { SystemConfig } from 'src/config';
|
||||
import { ImmichWorker } from 'src/enum';
|
||||
import { IAssetRepository, WithoutProperty } from 'src/interfaces/asset.interface';
|
||||
import { IConfigRepository } from 'src/interfaces/config.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';
|
||||
@@ -22,12 +23,14 @@ describe(SmartInfoService.name, () => {
|
||||
let machineLearningMock: Mocked<IMachineLearningRepository>;
|
||||
let searchMock: Mocked<ISearchRepository>;
|
||||
let systemMock: Mocked<ISystemMetadataRepository>;
|
||||
let configMock: Mocked<IConfigRepository>;
|
||||
|
||||
beforeEach(() => {
|
||||
({ sut, assetMock, databaseMock, jobMock, machineLearningMock, searchMock, systemMock } =
|
||||
({ sut, assetMock, databaseMock, jobMock, machineLearningMock, searchMock, systemMock, configMock } =
|
||||
newTestService(SmartInfoService));
|
||||
|
||||
assetMock.getByIds.mockResolvedValue([assetStub.image]);
|
||||
configMock.getWorker.mockReturnValue(ImmichWorker.MICROSERVICES);
|
||||
});
|
||||
|
||||
it('should work', () => {
|
||||
@@ -63,11 +66,11 @@ describe(SmartInfoService.name, () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('onBootstrapEvent', () => {
|
||||
describe('onConfigInit', () => {
|
||||
it('should return if not microservices', async () => {
|
||||
await sut.onBootstrap(ImmichWorker.API);
|
||||
configMock.getWorker.mockReturnValue(ImmichWorker.API);
|
||||
await sut.onConfigInit({ newConfig: systemConfigStub.machineLearningEnabled as SystemConfig });
|
||||
|
||||
expect(systemMock.get).not.toHaveBeenCalled();
|
||||
expect(searchMock.getDimensionSize).not.toHaveBeenCalled();
|
||||
expect(searchMock.setDimensionSize).not.toHaveBeenCalled();
|
||||
expect(searchMock.deleteAllSearchEmbeddings).not.toHaveBeenCalled();
|
||||
@@ -78,11 +81,8 @@ describe(SmartInfoService.name, () => {
|
||||
});
|
||||
|
||||
it('should return if machine learning is disabled', async () => {
|
||||
systemMock.get.mockResolvedValue(systemConfigStub.machineLearningDisabled);
|
||||
await sut.onConfigInit({ newConfig: systemConfigStub.machineLearningDisabled as SystemConfig });
|
||||
|
||||
await sut.onBootstrap(ImmichWorker.MICROSERVICES);
|
||||
|
||||
expect(systemMock.get).toHaveBeenCalledTimes(1);
|
||||
expect(searchMock.getDimensionSize).not.toHaveBeenCalled();
|
||||
expect(searchMock.setDimensionSize).not.toHaveBeenCalled();
|
||||
expect(searchMock.deleteAllSearchEmbeddings).not.toHaveBeenCalled();
|
||||
@@ -95,9 +95,8 @@ describe(SmartInfoService.name, () => {
|
||||
it('should return if model and DB dimension size are equal', async () => {
|
||||
searchMock.getDimensionSize.mockResolvedValue(512);
|
||||
|
||||
await sut.onBootstrap(ImmichWorker.MICROSERVICES);
|
||||
await sut.onConfigInit({ newConfig: systemConfigStub.machineLearningEnabled as SystemConfig });
|
||||
|
||||
expect(systemMock.get).toHaveBeenCalledTimes(1);
|
||||
expect(searchMock.getDimensionSize).toHaveBeenCalledTimes(1);
|
||||
expect(searchMock.setDimensionSize).not.toHaveBeenCalled();
|
||||
expect(searchMock.deleteAllSearchEmbeddings).not.toHaveBeenCalled();
|
||||
@@ -111,9 +110,8 @@ describe(SmartInfoService.name, () => {
|
||||
searchMock.getDimensionSize.mockResolvedValue(768);
|
||||
jobMock.getQueueStatus.mockResolvedValue({ isActive: false, isPaused: false });
|
||||
|
||||
await sut.onBootstrap(ImmichWorker.MICROSERVICES);
|
||||
await sut.onConfigInit({ newConfig: systemConfigStub.machineLearningEnabled as SystemConfig });
|
||||
|
||||
expect(systemMock.get).toHaveBeenCalledTimes(1);
|
||||
expect(searchMock.getDimensionSize).toHaveBeenCalledTimes(1);
|
||||
expect(searchMock.setDimensionSize).toHaveBeenCalledWith(512);
|
||||
expect(jobMock.getQueueStatus).toHaveBeenCalledTimes(1);
|
||||
@@ -126,9 +124,8 @@ describe(SmartInfoService.name, () => {
|
||||
searchMock.getDimensionSize.mockResolvedValue(768);
|
||||
jobMock.getQueueStatus.mockResolvedValue({ isActive: false, isPaused: true });
|
||||
|
||||
await sut.onBootstrap(ImmichWorker.MICROSERVICES);
|
||||
await sut.onConfigInit({ newConfig: systemConfigStub.machineLearningEnabled as SystemConfig });
|
||||
|
||||
expect(systemMock.get).toHaveBeenCalledTimes(1);
|
||||
expect(searchMock.getDimensionSize).toHaveBeenCalledTimes(1);
|
||||
expect(searchMock.setDimensionSize).toHaveBeenCalledWith(512);
|
||||
expect(jobMock.getQueueStatus).toHaveBeenCalledTimes(1);
|
||||
@@ -139,6 +136,22 @@ describe(SmartInfoService.name, () => {
|
||||
});
|
||||
|
||||
describe('onConfigUpdateEvent', () => {
|
||||
it('should return if not microservices', async () => {
|
||||
configMock.getWorker.mockReturnValue(ImmichWorker.API);
|
||||
await sut.onConfigUpdate({
|
||||
newConfig: systemConfigStub.machineLearningEnabled as SystemConfig,
|
||||
oldConfig: systemConfigStub.machineLearningEnabled as SystemConfig,
|
||||
});
|
||||
|
||||
expect(searchMock.getDimensionSize).not.toHaveBeenCalled();
|
||||
expect(searchMock.setDimensionSize).not.toHaveBeenCalled();
|
||||
expect(searchMock.deleteAllSearchEmbeddings).not.toHaveBeenCalled();
|
||||
expect(jobMock.getQueueStatus).not.toHaveBeenCalled();
|
||||
expect(jobMock.pause).not.toHaveBeenCalled();
|
||||
expect(jobMock.waitForQueueCompletion).not.toHaveBeenCalled();
|
||||
expect(jobMock.resume).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should return if machine learning is disabled', async () => {
|
||||
systemMock.get.mockResolvedValue(systemConfigStub.machineLearningDisabled);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user