mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
refactor(server): system config (#9517)
This commit is contained in:
parent
7f0f016f2e
commit
984aa8fb41
46 changed files with 599 additions and 770 deletions
52
server/src/utils/misc.spec.ts
Normal file
52
server/src/utils/misc.spec.ts
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import { getKeysDeep, unsetDeep } from 'src/utils/misc';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
describe('getKeysDeep', () => {
|
||||
it('should handle an empty object', () => {
|
||||
expect(getKeysDeep({})).toEqual([]);
|
||||
});
|
||||
|
||||
it('should list properties', () => {
|
||||
expect(
|
||||
getKeysDeep({
|
||||
foo: 'bar',
|
||||
flag: true,
|
||||
count: 42,
|
||||
}),
|
||||
).toEqual(['foo', 'flag', 'count']);
|
||||
});
|
||||
|
||||
it('should skip undefined properties', () => {
|
||||
expect(getKeysDeep({ foo: 'bar', hello: undefined })).toEqual(['foo']);
|
||||
});
|
||||
|
||||
it('should skip array indices', () => {
|
||||
expect(getKeysDeep({ foo: 'bar', hello: ['foo', 'bar'] })).toEqual(['foo', 'hello']);
|
||||
expect(getKeysDeep({ foo: 'bar', nested: { hello: ['foo', 'bar'] } })).toEqual(['foo', 'nested.hello']);
|
||||
});
|
||||
|
||||
it('should list nested properties', () => {
|
||||
expect(getKeysDeep({ foo: 'bar', hello: { world: true } })).toEqual(['foo', 'hello.world']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('unsetDeep', () => {
|
||||
it('should remove a property', () => {
|
||||
expect(unsetDeep({ hello: 'world', foo: 'bar' }, 'foo')).toEqual({ hello: 'world' });
|
||||
});
|
||||
|
||||
it('should remove the last property', () => {
|
||||
expect(unsetDeep({ foo: 'bar' }, 'foo')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should remove a nested property', () => {
|
||||
expect(unsetDeep({ foo: 'bar', nested: { enabled: true, count: 42 } }, 'nested.enabled')).toEqual({
|
||||
foo: 'bar',
|
||||
nested: { count: 42 },
|
||||
});
|
||||
});
|
||||
|
||||
it('should clean up an empty property', () => {
|
||||
expect(unsetDeep({ foo: 'bar', nested: { enabled: true } }, 'nested.enabled')).toEqual({ foo: 'bar' });
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue