mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-22 12:15:38 +00:00
* feat: Implement environment conversion utilities for Insomnia to Bruno migration fix tests fix: test feat: updated `toBrunoEnv` and merging functions to flatten environment data using dot-notation keys. added tests for `buildV5Environments` and `buildV4Environments` to verify flattened key behavior and shallow overrides. chore: update package-lock.json refactor: replace `flat` library with custom `flattenObject` utility for improved environment data flattening chore: remove package-lock.json updates feat: update `toBrunoEnv` to convert environment values to strings and adjust tests for flattened key behavior in Insomnia environment imports refactor: update flattening logic to use JavaScript-style square bracket notation for arrays and adjust related tests feat: enhance insomnia-to-bruno conversion by normalizing variables in requests, and add tests for v4 and v5 environment imports refactor: improve variable naming and streamline environment building logic in `buildV5Environments` and `buildV4Environments` functions test: add cleanup step to environment import tests and update expected version for new feature * revert package-lock.json changes * test: Add data-testid attributes to environment variable rows in EnvironmentVariables component
56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
import { describe, it, expect } from '@jest/globals';
|
|
import { flattenObject } from '../../src/utils/flatten';
|
|
|
|
describe('flattenObject', () => {
|
|
it('returns empty object for empty input object', () => {
|
|
expect(flattenObject({})).toEqual({});
|
|
});
|
|
|
|
it('flattens a simple nested object', () => {
|
|
const input = { user: { name: 'Tom', info: { id: 1 } } };
|
|
expect(flattenObject(input)).toEqual({
|
|
'user.name': 'Tom',
|
|
'user.info.id': 1
|
|
});
|
|
});
|
|
|
|
it('flattens arrays using JavaScript-style square bracket notation', () => {
|
|
const input = { tags: ['a', 'b'], nums: [1, 2] };
|
|
expect(flattenObject(input)).toEqual({
|
|
'tags[0]': 'a',
|
|
'tags[1]': 'b',
|
|
'nums[0]': 1,
|
|
'nums[1]': 2
|
|
});
|
|
});
|
|
|
|
it('handles null and primitive leaves correctly', () => {
|
|
const input = { a: null, b: true, c: 0, d: 'x' };
|
|
expect(flattenObject(input)).toEqual({
|
|
a: null,
|
|
b: true,
|
|
c: 0,
|
|
d: 'x'
|
|
});
|
|
});
|
|
|
|
it('flattens mixed nested objects and arrays', () => {
|
|
const input = {
|
|
user: { name: 'Tom', roles: ['admin', 'editor'] },
|
|
list: [{ id: 1 }, { id: 2 }]
|
|
};
|
|
expect(flattenObject(input)).toEqual({
|
|
'user.name': 'Tom',
|
|
'user.roles[0]': 'admin',
|
|
'user.roles[1]': 'editor',
|
|
'list[0].id': 1,
|
|
'list[1].id': 2
|
|
});
|
|
});
|
|
|
|
it('ignores empty arrays/objects (no keys produced for empty containers)', () => {
|
|
const input = { emptyObj: {}, emptyArr: [] };
|
|
expect(flattenObject(input)).toEqual({});
|
|
});
|
|
});
|