mirror of
https://github.com/immich-app/immich.git
synced 2025-12-27 17:24:58 +03:00
refactor(server): system config (#9517)
This commit is contained in:
105
server/test/fixtures/system-config.stub.ts
vendored
105
server/test/fixtures/system-config.stub.ts
vendored
@@ -1,33 +1,74 @@
|
||||
import { SystemConfigEntity, SystemConfigKey } from 'src/entities/system-config.entity';
|
||||
import { SystemConfig } from 'src/config';
|
||||
import { DeepPartial } from 'typeorm';
|
||||
|
||||
export const systemConfigStub: Record<string, SystemConfigEntity[]> = {
|
||||
defaults: [],
|
||||
enabled: [
|
||||
{ key: SystemConfigKey.OAUTH_ENABLED, value: true },
|
||||
{ key: SystemConfigKey.OAUTH_AUTO_REGISTER, value: true },
|
||||
{ key: SystemConfigKey.OAUTH_AUTO_LAUNCH, value: false },
|
||||
{ key: SystemConfigKey.OAUTH_BUTTON_TEXT, value: 'OAuth' },
|
||||
],
|
||||
disabled: [{ key: SystemConfigKey.PASSWORD_LOGIN_ENABLED, value: false }],
|
||||
noAutoRegister: [
|
||||
{ key: SystemConfigKey.OAUTH_ENABLED, value: true },
|
||||
{ key: SystemConfigKey.OAUTH_AUTO_LAUNCH, value: false },
|
||||
{ key: SystemConfigKey.OAUTH_AUTO_REGISTER, value: false },
|
||||
{ key: SystemConfigKey.OAUTH_BUTTON_TEXT, value: 'OAuth' },
|
||||
],
|
||||
override: [
|
||||
{ key: SystemConfigKey.OAUTH_ENABLED, value: true },
|
||||
{ key: SystemConfigKey.OAUTH_AUTO_REGISTER, value: true },
|
||||
{ key: SystemConfigKey.OAUTH_MOBILE_OVERRIDE_ENABLED, value: true },
|
||||
{ key: SystemConfigKey.OAUTH_MOBILE_REDIRECT_URI, value: 'http://mobile-redirect' },
|
||||
{ key: SystemConfigKey.OAUTH_BUTTON_TEXT, value: 'OAuth' },
|
||||
],
|
||||
withDefaultStorageQuota: [
|
||||
{ key: SystemConfigKey.OAUTH_ENABLED, value: true },
|
||||
{ key: SystemConfigKey.OAUTH_AUTO_REGISTER, value: true },
|
||||
{ key: SystemConfigKey.OAUTH_DEFAULT_STORAGE_QUOTA, value: 1 },
|
||||
],
|
||||
deleteDelay30: [{ key: SystemConfigKey.USER_DELETE_DELAY, value: 30 }],
|
||||
libraryWatchEnabled: [{ key: SystemConfigKey.LIBRARY_WATCH_ENABLED, value: true }],
|
||||
libraryWatchDisabled: [{ key: SystemConfigKey.LIBRARY_WATCH_ENABLED, value: false }],
|
||||
};
|
||||
export const systemConfigStub = {
|
||||
enabled: {
|
||||
oauth: {
|
||||
enabled: true,
|
||||
autoRegister: true,
|
||||
autoLaunch: false,
|
||||
buttonText: 'OAuth',
|
||||
},
|
||||
},
|
||||
disabled: {
|
||||
passwordLogin: {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
noAutoRegister: {
|
||||
oauth: {
|
||||
enabled: true,
|
||||
autoRegister: false,
|
||||
autoLaunch: false,
|
||||
buttonText: 'OAuth',
|
||||
},
|
||||
},
|
||||
override: {
|
||||
oauth: {
|
||||
enabled: true,
|
||||
autoRegister: true,
|
||||
mobileOverrideEnabled: true,
|
||||
mobileRedirectUri: 'http://mobile-redirect',
|
||||
buttonText: 'OAuth',
|
||||
},
|
||||
},
|
||||
withDefaultStorageQuota: {
|
||||
oauth: {
|
||||
enabled: true,
|
||||
autoRegister: true,
|
||||
defaultStorageQuota: 1,
|
||||
},
|
||||
},
|
||||
deleteDelay30: {
|
||||
user: {
|
||||
deleteDelay: 30,
|
||||
},
|
||||
},
|
||||
libraryWatchEnabled: {
|
||||
library: {
|
||||
watch: {
|
||||
enabled: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
libraryWatchDisabled: {
|
||||
library: {
|
||||
watch: {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
libraryScan: {
|
||||
library: {
|
||||
scan: {
|
||||
enabled: true,
|
||||
cronExpression: '0 0 * * *',
|
||||
},
|
||||
},
|
||||
},
|
||||
machineLearningDisabled: {
|
||||
machineLearning: {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
} satisfies Record<string, DeepPartial<SystemConfig>>;
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
import { SystemConfigCore } from 'src/cores/system-config.core';
|
||||
import { ISystemConfigRepository } from 'src/interfaces/system-config.interface';
|
||||
import { Mocked, vitest } from 'vitest';
|
||||
|
||||
export const newSystemConfigRepositoryMock = (reset = true): Mocked<ISystemConfigRepository> => {
|
||||
if (reset) {
|
||||
SystemConfigCore.reset();
|
||||
}
|
||||
|
||||
return {
|
||||
fetchStyle: vitest.fn(),
|
||||
load: vitest.fn().mockResolvedValue([]),
|
||||
readFile: vitest.fn(),
|
||||
saveAll: vitest.fn().mockResolvedValue([]),
|
||||
deleteKeys: vitest.fn(),
|
||||
};
|
||||
};
|
||||
@@ -1,9 +1,16 @@
|
||||
import { SystemConfigCore } from 'src/cores/system-config.core';
|
||||
import { ISystemMetadataRepository } from 'src/interfaces/system-metadata.interface';
|
||||
import { Mocked, vitest } from 'vitest';
|
||||
|
||||
export const newSystemMetadataRepositoryMock = (): Mocked<ISystemMetadataRepository> => {
|
||||
export const newSystemMetadataRepositoryMock = (reset = true): Mocked<ISystemMetadataRepository> => {
|
||||
if (reset) {
|
||||
SystemConfigCore.reset();
|
||||
}
|
||||
|
||||
return {
|
||||
get: vitest.fn() as any,
|
||||
set: vitest.fn(),
|
||||
readFile: vitest.fn(),
|
||||
fetchStyle: vitest.fn(),
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user