bruno/packages/bruno-cli/tests/runner/prepare-request.spec.js
Antti Sonkeri 9c11e27d1c
fix: decomment not working in json body (#1819)
Request body json was not decommented if json parsing fails, which
would happen if variables are not quoted.

Fixes usebruno#888
2024-06-19 16:18:36 +05:30

22 lines
819 B
JavaScript

const { describe, it, expect } = require('@jest/globals');
const prepareRequest = require('../../src/runner/prepare-request');
describe('prepare-request: prepareRequest', () => {
describe('Decomments request body', () => {
it('If request body is valid JSON', async () => {
const body = { mode: 'json', json: '{\n"test": "{{someVar}}" // comment\n}' };
const expected = { test: '{{someVar}}' };
const result = prepareRequest({ body });
expect(result.data).toEqual(expected);
});
it('If request body is not valid JSON', async () => {
const body = { mode: 'json', json: '{\n"test": {{someVar}} // comment\n}' };
const expected = '{\n"test": {{someVar}} \n}';
const result = prepareRequest({ body });
expect(result.data).toEqual(expected);
});
});
});