mirror of
https://github.com/Kong/insomnia.git
synced 2026-05-24 16:51:06 -04:00
fix: preserve empty strings during export (#8727)
This commit is contained in:
49
packages/insomnia/src/common/__tests__/insomnia-v5.test.ts
Normal file
49
packages/insomnia/src/common/__tests__/insomnia-v5.test.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import * as models from '../../models';
|
||||
import { getInsomniaV5DataExport } from '../insomnia-v5';
|
||||
|
||||
describe('getInsomniaV5DataExport', () => {
|
||||
it('should preserve empty string environments', async () => {
|
||||
const workspace = await models.workspace.create({
|
||||
_id: 'wrk_id',
|
||||
name: 'Workspace Name',
|
||||
created: 0,
|
||||
modified: 0,
|
||||
description: 'workspace description',
|
||||
});
|
||||
|
||||
await models.environment.create({
|
||||
_id: 'env_id',
|
||||
name: 'Environment Name',
|
||||
parentId: workspace._id,
|
||||
created: 0,
|
||||
modified: 0,
|
||||
data: {
|
||||
foo: 'bar',
|
||||
empty: '',
|
||||
},
|
||||
});
|
||||
|
||||
const result = await getInsomniaV5DataExport({ workspaceId: 'wrk_id', includePrivateEnvironments: false });
|
||||
|
||||
expect(result).toEqual(`type: collection.insomnia.rest/5.0
|
||||
name: Workspace Name
|
||||
meta:
|
||||
id: wrk_id
|
||||
created: 0
|
||||
modified: 0
|
||||
description: workspace description
|
||||
environments:
|
||||
name: Environment Name
|
||||
meta:
|
||||
id: env_id
|
||||
created: 0
|
||||
modified: 0
|
||||
isPrivate: false
|
||||
data:
|
||||
foo: bar
|
||||
empty: ""
|
||||
`);
|
||||
});
|
||||
});
|
||||
@@ -42,12 +42,7 @@ import {
|
||||
type WithExportType<T extends models.BaseModel> = T & { _type: string };
|
||||
|
||||
function filterEmptyValue(value: string | number | boolean | null | undefined) {
|
||||
return (
|
||||
value !== null &&
|
||||
value !== undefined &&
|
||||
value !== '' &&
|
||||
!(typeof value === 'object' && Object.keys(value).length === 0)
|
||||
);
|
||||
return value !== null && value !== undefined && !(typeof value === 'object' && Object.keys(value).length === 0);
|
||||
}
|
||||
|
||||
function removeEmptyFields(data: any): any {
|
||||
|
||||
Reference in New Issue
Block a user