Files
bruno/packages/bruno-cli/tests/runner/interpolate-vars.spec.js
2026-05-15 13:55:47 +05:30

51 lines
1.3 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);
});
});
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');
});
});