mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-09 00:18:00 +01:00
fix: do not split non string values (#4346)
This commit is contained in:
parent
9f35c2187f
commit
7095e87061
@ -5,15 +5,16 @@ test('should generate all combinations correctly', () => {
|
||||
sessionId: '1,2',
|
||||
appName: 'a,b,c',
|
||||
channels: 'internet',
|
||||
nonString: 1,
|
||||
};
|
||||
|
||||
const expectedCombinations = [
|
||||
{ sessionId: '1', appName: 'a', channels: 'internet' },
|
||||
{ sessionId: '1', appName: 'b', channels: 'internet' },
|
||||
{ sessionId: '1', appName: 'c', channels: 'internet' },
|
||||
{ sessionId: '2', appName: 'a', channels: 'internet' },
|
||||
{ sessionId: '2', appName: 'b', channels: 'internet' },
|
||||
{ sessionId: '2', appName: 'c', channels: 'internet' },
|
||||
{ sessionId: '1', appName: 'a', channels: 'internet', nonString: 1 },
|
||||
{ sessionId: '1', appName: 'b', channels: 'internet', nonString: 1 },
|
||||
{ sessionId: '1', appName: 'c', channels: 'internet', nonString: 1 },
|
||||
{ sessionId: '2', appName: 'a', channels: 'internet', nonString: 1 },
|
||||
{ sessionId: '2', appName: 'b', channels: 'internet', nonString: 1 },
|
||||
{ sessionId: '2', appName: 'c', channels: 'internet', nonString: 1 },
|
||||
];
|
||||
|
||||
const actualCombinations = generateObjectCombinations(obj);
|
||||
|
@ -1,13 +1,16 @@
|
||||
type Dict<T> = { [K in keyof T]: string[] };
|
||||
|
||||
export const splitByComma = <T extends Record<string, string>>(
|
||||
export const splitByComma = <T extends Record<string, unknown>>(
|
||||
obj: T,
|
||||
): Dict<T> =>
|
||||
Object.fromEntries(
|
||||
Object.entries(obj).map(([key, value]) => [key, value.split(',')]),
|
||||
Object.entries(obj).map(([key, value]) => [
|
||||
key,
|
||||
typeof value === 'string' ? value.split(',') : [value],
|
||||
]),
|
||||
) as Dict<T>;
|
||||
|
||||
export const generateCombinations = <T extends Record<string, any>>(
|
||||
export const generateCombinations = <T extends Record<string, unknown>>(
|
||||
obj: Dict<T>,
|
||||
): T[] => {
|
||||
const keys = Object.keys(obj) as (keyof T)[];
|
||||
|
Loading…
Reference in New Issue
Block a user