mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
|
|
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' });
|
||
|
|
});
|
||
|
|
});
|