Files
threshold-ui/addons/api/tests/unit/utils/flatten-nested-object-test.js
Lisbet Alvarez 3ba93927fe Update copyright headers (#3146)
* empty commit

* Add missing copyright headers

* chore: 🤖 update copywrite config file with correct year

* Add missing copyright headers

* empty commit (gh action merge checks are stuck)
2026-01-28 17:09:06 -08:00

48 lines
1.1 KiB
JavaScript

/**
* Copyright IBM Corp. 2021, 2026
* SPDX-License-Identifier: BUSL-1.1
*/
import { flattenObject } from 'api/utils/flatten-nested-object';
import { module, test } from 'qunit';
module('Unit | Utility | flatten-nested-object', function () {
test('it flattens a nested object to single level object', function (assert) {
const input = {
a: 1,
b: { c: 2, d: 3, e: { f: { g: { h: 10 } } } },
};
const expected = {
a: 1,
'b.c': 2,
'b.d': 3,
'b.e.f.g.h': 10,
};
assert.deepEqual(flattenObject(input), expected);
});
test('removes keys with null/empty values', function (assert) {
const inputOne = {
a: null,
b: { c: 2 },
d: {
e: { f: { g: { h: '' } } },
},
i: 0,
j: false,
};
const inputTwo = {
d: { e: null },
};
const expectedResultOne = {
'b.c': 2,
i: 0,
j: false,
};
const expectedResultTwo = {};
assert.deepEqual(flattenObject(inputOne), expectedResultOne);
assert.deepEqual(flattenObject(inputTwo), expectedResultTwo);
});
});