fixes tests for the file body pr (#3940)

fixes tests for bruno-app and bruno-electron
This commit is contained in:
lohit
2025-02-04 21:56:34 +05:30
committed by GitHub
parent c9b2aa7760
commit cb501c70aa
3 changed files with 10 additions and 10 deletions

View File

@@ -113,11 +113,9 @@ describe('curlToJson', () => {
isDataBinary: true,
data: [
{
name: 'file',
value: ['/path/to/file'],
enabled: true,
filePath: '/path/to/file',
contentType: 'application/json;charset=utf-8',
type: 'file'
selected: true
}
]
});

View File

@@ -176,10 +176,10 @@ const setAuthHeaders = (axiosRequest, request, collectionRoot) => {
return axiosRequest;
};
const prepareRequest = async (item, collection, abortController) => {
const prepareRequest = async (item, collection = {}, abortController) => {
const request = item.draft ? item.draft.request : item.request;
const collectionRoot = get(collection, 'root', {});
const collectionPath = collection.pathname;
const collectionPath = collection?.pathname;
const headers = {};
let contentTypeDefined = false;
let url = request.url;
@@ -191,7 +191,7 @@ const prepareRequest = async (item, collection, abortController) => {
}
});
const scriptFlow = collection.brunoConfig?.scripts?.flow ?? 'sandwich';
const scriptFlow = collection?.brunoConfig?.scripts?.flow ?? 'sandwich';
const requestTreePath = getTreePathFromCollectionToItem(collection, item);
if (requestTreePath && requestTreePath.length > 0) {
mergeHeaders(collection, request, requestTreePath);

View File

@@ -7,15 +7,17 @@ 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 = '{\n"test": "{{someVar}}" \n}';
const result = prepareRequest({ request: { body } }, {});
const expected = `{
\"test\": \"{{someVar}}\"
}`;
const result = await prepareRequest({ request: { body }, collection: { pathname: '' } });
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({ request: { body } }, {});
const result = await prepareRequest({ request: { body }, collection: { pathname: '' } });
expect(result.data).toEqual(expected);
});