mirror of
https://github.com/immich-app/immich.git
synced 2025-12-09 15:03:54 +09:00
refactor(server): system config (#9517)
This commit is contained in:
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' });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user