1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-31 00:16:47 +01:00
unleash.unleash/src/lib/util/flattenPayload.test.ts
Nuno Góis 422af36d2d
chore: flatten payload util (#6531)
https://linear.app/unleash/issue/2-2029/support-filtering-on-nested-properties

This will allow us to support and suggest payload subproperties in the
action filters.
2024-03-13 11:10:44 +00:00

36 lines
813 B
TypeScript

import { flattenPayload } from './flattenPayload';
describe('flattenPayload', () => {
it('should flatten a payload', () => {
const payload = {
a: 1,
b: {
c: 2,
d: [3, 4],
e: {
f: 5,
},
},
};
expect(flattenPayload(payload)).toEqual({
a: 1,
'b.c': 2,
'b.d[0]': 3,
'b.d[1]': 4,
'b.e.f': 5,
});
});
it('should handle conflicting keys gracefully by prioritizing later keys', () => {
const payload = {
a: {
b: 1,
},
'a.b': 2,
};
expect(flattenPayload(payload)).toEqual({
'a.b': 2,
});
});
});