59 lines
1.5 KiB
TypeScript
59 lines
1.5 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { config, defaultConfig, mergeConfig, type Config, stripPrivateFields } from './config';
|
|
|
|
describe('Config', () => {
|
|
it('should be export a build time config', () => {
|
|
expect(config).toBeTruthy();
|
|
});
|
|
|
|
it('should be able to merge with POJO', () => {
|
|
const merged = mergeConfig(defaultConfig, {
|
|
subtitle: "Homer's favorite neighboor",
|
|
services: [
|
|
{
|
|
title: 'favorite occupations',
|
|
items: [
|
|
{
|
|
title: 'anoy homer',
|
|
customKey: 'all the time'
|
|
}
|
|
]
|
|
}
|
|
]
|
|
});
|
|
|
|
expect(merged.title).toEqual('Flanders');
|
|
expect(merged.services).toHaveLength(1);
|
|
expect(merged.services[0].title).toEqual('favorite occupations');
|
|
expect(merged.services[0].items).toHaveLength(1);
|
|
expect(merged.services[0].items[0].title).toEqual('anoy homer');
|
|
expect(merged.services[0].items[0].customKey).toEqual('all the time');
|
|
});
|
|
|
|
it('should be able to strip custom keys', () => {
|
|
const custom: Config = {
|
|
title: 'custom',
|
|
secret: {secret: 'some secret'},
|
|
services: [
|
|
{
|
|
title: 'top services',
|
|
secret: 'secret',
|
|
items: [
|
|
{
|
|
title: 'top service',
|
|
url: 'somewhere',
|
|
secret: 'secret'
|
|
}
|
|
]
|
|
}
|
|
]
|
|
};
|
|
|
|
const stripped: Config = stripPrivateFields(custom);
|
|
|
|
expect(stripped.secret).toBeUndefined();
|
|
expect(stripped.services[0].secret).toBeUndefined();
|
|
expect(stripped.services[0].items[0].secret).toBeUndefined();
|
|
});
|
|
});
|