Skip to content

Commit 96c6d9f

Browse files
authored
Merge pull request #825 from fractal-analytics-platform/body-request-normalizer
Added body request normalizer
2 parents c1b4f52 + 973ec70 commit 96c6d9f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1296
-1047
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
*Note: Numbers like (\#123) point to closed Pull Requests on the fractal-web repository.*
22

3+
# Unreleased
4+
5+
* Added body request normalizer (\#825);
6+
37
# 1.19.3
48

59
* Added "Open in Feature Explorer" link and `PUBLIC_FRACTAL_FEATURE_EXPLORER_URL` environment variable (\#820);

components/__tests__/utils.test.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, expect } from 'vitest';
2-
import { stripNullAndEmptyObjectsAndArrays } from '../src/lib/common/utils';
2+
import { stripNullAndEmptyObjectsAndArrays, _normalize } from '../src/lib/common/utils';
33

44
describe('utils', () => {
55
it('should strip data objects correctly', () => {
@@ -39,4 +39,44 @@ describe('utils', () => {
3939
}
4040
});
4141
});
42+
43+
it('should normalize a complex nested object and track paths', () => {
44+
const payload = {
45+
foo: {
46+
bar: [{ baz: ' Value 1\u200B ' }, { baz: ' Value 2 ' }, null, { baz: undefined }],
47+
qux: ' Some text\u200B '
48+
},
49+
quux: {
50+
corge: ' Another value ',
51+
grault: [{ garply: ' Nested value ' }, { garply: null }],
52+
'key_with_space ': true
53+
},
54+
'key_with_space ': true
55+
};
56+
57+
const normalizedPaths = _normalize(payload);
58+
59+
expect(payload).toEqual({
60+
foo: {
61+
bar: [{ baz: 'Value 1' }, { baz: 'Value 2' }, null, { baz: undefined }],
62+
qux: 'Some text'
63+
},
64+
quux: {
65+
corge: 'Another value',
66+
grault: [{ garply: 'Nested value' }, { garply: null }],
67+
key_with_space: true
68+
},
69+
key_with_space: true
70+
});
71+
72+
expect(normalizedPaths).toEqual([
73+
'foo.bar[0].baz',
74+
'foo.bar[1].baz',
75+
'foo.qux',
76+
'quux.corge',
77+
'quux.grault[0].garply',
78+
'quux',
79+
'root'
80+
]);
81+
});
4282
});

0 commit comments

Comments
 (0)