mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-31 00:16:47 +01:00
422af36d2d
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.
36 lines
813 B
TypeScript
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,
|
|
});
|
|
});
|
|
});
|