refactor(server): feature flags (#9492)

This commit is contained in:
Jason Rasmussen
2024-05-14 15:31:36 -04:00
committed by GitHub
parent 5583635947
commit 0f129cae4a
11 changed files with 59 additions and 132 deletions

View File

@@ -1,7 +1,6 @@
import { BadRequestException } from '@nestjs/common';
import { SystemConfig } from 'src/config';
import { FeatureFlag, SystemConfigCore } from 'src/cores/system-config.core';
import { SystemConfigKey, SystemConfigKeyPaths } from 'src/entities/system-config.entity';
import { SystemConfigCore } from 'src/cores/system-config.core';
import { IAssetRepository } from 'src/interfaces/asset.interface';
import { IEventRepository } from 'src/interfaces/event.interface';
import {
@@ -368,32 +367,5 @@ describe(JobService.name, () => {
expect(jobMock.queueAll).not.toHaveBeenCalled();
});
}
const featureTests: Array<{ queue: QueueName; feature: FeatureFlag; configKey: SystemConfigKeyPaths }> = [
{
queue: QueueName.SMART_SEARCH,
feature: FeatureFlag.SMART_SEARCH,
configKey: SystemConfigKey.MACHINE_LEARNING_CLIP_ENABLED,
},
{
queue: QueueName.FACE_DETECTION,
feature: FeatureFlag.FACIAL_RECOGNITION,
configKey: SystemConfigKey.MACHINE_LEARNING_FACIAL_RECOGNITION_ENABLED,
},
{
queue: QueueName.FACIAL_RECOGNITION,
feature: FeatureFlag.FACIAL_RECOGNITION,
configKey: SystemConfigKey.MACHINE_LEARNING_FACIAL_RECOGNITION_ENABLED,
},
];
for (const { queue, feature, configKey } of featureTests) {
it(`should throw an error if attempting to queue ${queue} when ${feature} is disabled`, async () => {
configMock.load.mockResolvedValue([{ key: configKey, value: false }]);
jobMock.getQueueStatus.mockResolvedValue({ isActive: false, isPaused: false });
await expect(sut.handleCommand(queue, { command: JobCommand.START, force: false })).rejects.toThrow();
});
}
});
});