Files
bruno/packages/bruno-cli/tests/runner/interpolate-vars.spec.js
Sid a3e3199490 fix: multipart/mixed and multipart/form-data interpolation and generic request behaviour (#8087)
* fix: multipart spec additions and interpolation fixes

* test(cli): add interpolation multipart  tests

* Update packages/bruno-tests/collection/multipart/multipart-mixed-form-data-parse.bru

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* chore: remove assert as curl also gives the same result

* chore: codestyle

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2026-05-25 20:05:50 +05:30

103 lines
2.9 KiB
JavaScript

const { describe, it, expect } = require('@jest/globals');
const interpolateVars = require('../../src/runner/interpolate-vars');
describe('interpolate-vars: interpolateVars', () => {
it('keeps stream-backed JSON request bodies intact', () => {
const streamPayload = {
pipe: jest.fn(),
path: '/tmp/allocations.json'
};
const request = {
method: 'POST',
mode: 'file',
url: 'http://api.example/upload',
headers: { 'content-type': 'application/json' },
data: streamPayload
};
const result = interpolateVars(request, { shouldNotApply: 'value' }, null, null);
expect(result.data).toBe(streamPayload);
});
it('preserves raw string body when Content-Type is multipart/mixed', () => {
const rawMultipartBody = [
'--TestBoundary123',
'Content-Type: application/json',
'',
'{"test": true}',
'--TestBoundary123--',
''
].join('\r\n');
const request = {
method: 'POST',
mode: 'text',
url: 'https://httpbin.dev/post',
headers: { 'content-type': 'multipart/mixed; boundary=TestBoundary123' },
data: rawMultipartBody
};
const result = interpolateVars(request, {}, null, null);
expect(result.data).toBe(rawMultipartBody);
});
it('interpolates variables in raw multipart/mixed string body', () => {
const boundary = 'CustomBoundary123';
const rawMultipartBody = [
`--${boundary}`,
'Content-Type: text/plain',
'',
'Token: {{token}}',
`--${boundary}`,
'Content-Type: application/json',
'',
'{"id": "{{id}}", "msg": "{{msg}}"}',
`--${boundary}--`,
''
].join('\r\n');
const request = {
method: 'POST',
mode: 'text',
url: 'https://api.example/send',
headers: { 'content-type': `multipart/mixed; boundary=${boundary}` },
data: rawMultipartBody
};
const result = interpolateVars(request, { token: 'abc123', id: 42, msg: 'hello' }, null, null);
expect(result.data).toContain('Token: abc123');
expect(result.data).toContain('{"id": "42", "msg": "hello"}');
expect(result.data).toContain(`--${boundary}`);
expect(result.data).toContain(`--${boundary}--`);
});
});
describe('interpolate-vars: api key header name sidecar', () => {
it('interpolates apiKeyHeaderName in lockstep with interpolated header keys', () => {
const request = {
url: 'https://example.com',
mode: 'none',
headers: {
'{{api_header_name}}': '{{api_key_value}}'
},
apiKeyHeaderName: '{{api_header_name}}',
pathParams: []
};
interpolateVars(
request,
{
api_header_name: 'X-API-Key',
api_key_value: 'secret-key-value'
},
{},
{}
);
expect(request.headers).toEqual({
'X-API-Key': 'secret-key-value'
});
expect(request.apiKeyHeaderName).toEqual('X-API-Key');
});
});