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',
|
sessionId: '1,2',
|
||||||
appName: 'a,b,c',
|
appName: 'a,b,c',
|
||||||
channels: 'internet',
|
channels: 'internet',
|
||||||
|
nonString: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
const expectedCombinations = [
|
const expectedCombinations = [
|
||||||
{ sessionId: '1', appName: 'a', channels: 'internet' },
|
{ sessionId: '1', appName: 'a', channels: 'internet', nonString: 1 },
|
||||||
{ sessionId: '1', appName: 'b', channels: 'internet' },
|
{ sessionId: '1', appName: 'b', channels: 'internet', nonString: 1 },
|
||||||
{ sessionId: '1', appName: 'c', channels: 'internet' },
|
{ sessionId: '1', appName: 'c', channels: 'internet', nonString: 1 },
|
||||||
{ sessionId: '2', appName: 'a', channels: 'internet' },
|
{ sessionId: '2', appName: 'a', channels: 'internet', nonString: 1 },
|
||||||
{ sessionId: '2', appName: 'b', channels: 'internet' },
|
{ sessionId: '2', appName: 'b', channels: 'internet', nonString: 1 },
|
||||||
{ sessionId: '2', appName: 'c', channels: 'internet' },
|
{ sessionId: '2', appName: 'c', channels: 'internet', nonString: 1 },
|
||||||
];
|
];
|
||||||
|
|
||||||
const actualCombinations = generateObjectCombinations(obj);
|
const actualCombinations = generateObjectCombinations(obj);
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
type Dict<T> = { [K in keyof T]: string[] };
|
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,
|
obj: T,
|
||||||
): Dict<T> =>
|
): Dict<T> =>
|
||||||
Object.fromEntries(
|
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>;
|
) as Dict<T>;
|
||||||
|
|
||||||
export const generateCombinations = <T extends Record<string, any>>(
|
export const generateCombinations = <T extends Record<string, unknown>>(
|
||||||
obj: Dict<T>,
|
obj: Dict<T>,
|
||||||
): T[] => {
|
): T[] => {
|
||||||
const keys = Object.keys(obj) as (keyof T)[];
|
const keys = Object.keys(obj) as (keyof T)[];
|
||||||
|
Loading…
Reference in New Issue
Block a user