1
0
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:
Mateusz Kwasniewski 2023-07-26 12:32:08 +02:00 committed by GitHub
parent 9f35c2187f
commit 7095e87061
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 9 deletions

View File

@ -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);

View File

@ -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)[];