Files
bruno/packages/bruno-cli/tests/utils/axios-instance.spec.js
James b91f9ba5be fix: preserve axios default Accept header when setting User-Agent (#7820)
Assigning `defaults.headers.common = { 'User-Agent': ... }` replaced the
entire common headers object, nuking axios's built-in default:

  Accept: application/json, text/plain, */*

This caused servers relying on content-negotiation to receive requests
with no Accept header. Fix by extending the existing object with a
property assignment instead.

Add regression tests for both electron and CLI axios instances verifying
that Accept is preserved and User-Agent is set correctly.

Co-authored-by: Pragadesh-45 <temporaryg7904@gmail.com>
2026-05-05 21:38:12 +05:30

38 lines
1.3 KiB
JavaScript

const { describe, it, expect } = require('@jest/globals');
const { makeAxiosInstance } = require('../../src/utils/axios-instance');
function createStubAdapter() {
let capturedConfig = null;
const adapter = (config) => {
capturedConfig = config;
return Promise.resolve({ data: {}, status: 200, statusText: 'OK', headers: {}, config });
};
adapter.getConfig = () => capturedConfig;
return adapter;
}
describe('makeAxiosInstance', () => {
it('setting User-Agent does not clobber the axios default Accept header', async () => {
const stubAdapter = createStubAdapter();
const instance = makeAxiosInstance();
await instance({ url: 'https://api.example.com/test', method: 'get', adapter: stubAdapter });
// axios.create() sets Accept by default; assigning a new object to defaults.headers.common
// would nuke it. Guard against that regression.
expect(stubAdapter.getConfig().headers['Accept']).toMatch(/application\/json/);
});
it('sets User-Agent header to bruno-runtime version', async () => {
const stubAdapter = createStubAdapter();
const instance = makeAxiosInstance();
await instance({ url: 'https://api.example.com/test', method: 'get', adapter: stubAdapter });
expect(stubAdapter.getConfig().headers['User-Agent']).toMatch(/^bruno-runtime\//);
});
});