mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-11 09:51:30 +00:00
fix: storing status in example for yml file (#6876)
* fix: storing status in example for yml file * fix: temporary check for tests * fix: temporary check for tests * fix: temporary check for tests * fix: temporary check for tests * fix: temporary check for tests * fix: temporary check for tests * fix: temporary check for tests * fix: temporary check for tests * fix: temporary check for tests * fix: temporary check for tests * fix: temporary check for tests * fix: temporary check for tests * fix: test cases for status and statusText * chore: removed logs * fix: test cases for response status and text * fix: test cases for response status and text * fix: resolved comments * fix: openapi test import test cases * chore: removed console logs * fix: status type in response example while import/export of collection * fix: postman to bruno import --------- Co-authored-by: shubh-bruno <shubh-bruno@shubh-bruno.local>
This commit is contained in:
@@ -464,7 +464,7 @@ const CollectionItem = ({ item, collectionUid, collectionPathname, searchText })
|
||||
const exampleData = {
|
||||
name: name,
|
||||
description: description,
|
||||
status: '200',
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
headers: [],
|
||||
body: {
|
||||
|
||||
@@ -41,7 +41,7 @@ export const addResponseExample = (state, action) => {
|
||||
body: requestBody
|
||||
},
|
||||
response: {
|
||||
status: String(example.status ?? ''),
|
||||
status: example.status ? Number(example.status) : null,
|
||||
statusText: String(example.statusText ?? (example.status ? (statusCodePhraseMap[Number(example.status)] ?? '') : '')),
|
||||
headers: (example.headers || []).map((header) => ({
|
||||
uid: uuid(),
|
||||
@@ -717,7 +717,13 @@ export const updateResponseExampleResponse = (state, action) => {
|
||||
const example = item.draft.examples.find((e) => e.uid === exampleUid);
|
||||
if (!example) return;
|
||||
|
||||
example.response = { ...example.response, ...response };
|
||||
// Ensure status is a number if provided
|
||||
const processedResponse = { ...response };
|
||||
if (processedResponse.status !== undefined) {
|
||||
processedResponse.status = processedResponse.status ? Number(processedResponse.status) : null;
|
||||
}
|
||||
|
||||
example.response = { ...example.response, ...processedResponse };
|
||||
};
|
||||
|
||||
export const updateResponseExampleDetails = (state, action) => {
|
||||
@@ -1319,7 +1325,7 @@ export const updateResponseExampleStatusCode = (state, action) => {
|
||||
example.response = {};
|
||||
}
|
||||
|
||||
example.response.status = String(statusCode ?? '');
|
||||
example.response.status = statusCode ? Number(statusCode) : null;
|
||||
};
|
||||
|
||||
export const updateResponseExampleStatusText = (state, action) => {
|
||||
|
||||
@@ -670,6 +670,19 @@ export const transformCollectionToSaveToExportAsFile = (collection, options = {}
|
||||
export const transformRequestToSaveToFilesystem = (item) => {
|
||||
const _item = item.draft ? item.draft : item;
|
||||
|
||||
// Transform examples to ensure status is a number
|
||||
const transformExamples = (examples = []) => {
|
||||
return map(examples, (example) => ({
|
||||
...example,
|
||||
response: example.response ? {
|
||||
...example.response,
|
||||
status: example.response.status !== undefined && example.response.status !== null
|
||||
? Number(example.response.status)
|
||||
: null
|
||||
} : example.response
|
||||
}));
|
||||
};
|
||||
|
||||
const itemToSave = {
|
||||
uid: _item.uid,
|
||||
type: _item.type,
|
||||
@@ -677,7 +690,7 @@ export const transformRequestToSaveToFilesystem = (item) => {
|
||||
seq: _item.seq,
|
||||
settings: _item.settings,
|
||||
tags: _item.tags,
|
||||
examples: _item.examples || [],
|
||||
examples: transformExamples(_item.examples || []),
|
||||
request: {
|
||||
method: _item.request.method,
|
||||
url: _item.request.url,
|
||||
@@ -1501,7 +1514,7 @@ export const transformExampleToDraft = (example, newExample) => {
|
||||
exampleToDraft.description = newExample.description;
|
||||
}
|
||||
if (newExample.status) {
|
||||
exampleToDraft.response.status = String(newExample.status);
|
||||
exampleToDraft.response.status = Number(newExample.status);
|
||||
}
|
||||
if (newExample.statusText) {
|
||||
exampleToDraft.response.statusText = newExample.statusText;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { BrunoError } from 'utils/common/error';
|
||||
import { validateSchema, transformItemsInCollection, updateUidsInCollection, hydrateSeqInCollection } from './common';
|
||||
import { transformExampleStatusInCollection } from '@usebruno/common';
|
||||
|
||||
const stripExportMetadata = (collection) => {
|
||||
delete collection.exportedAt;
|
||||
@@ -13,6 +14,7 @@ export const processBrunoCollection = async (jsonData) => {
|
||||
collection = hydrateSeqInCollection(collection);
|
||||
collection = updateUidsInCollection(collection);
|
||||
collection = transformItemsInCollection(collection);
|
||||
collection = transformExampleStatusInCollection(collection);
|
||||
await validateSchema(collection);
|
||||
return collection;
|
||||
} catch (err) {
|
||||
|
||||
@@ -2,6 +2,7 @@ import each from 'lodash/each';
|
||||
import { uuid } from 'utils/common';
|
||||
import { BrunoError } from 'utils/common/error';
|
||||
import { validateSchema, updateUidsInCollection, hydrateSeqInCollection } from './common';
|
||||
import { transformExampleStatusInCollection } from '@usebruno/common';
|
||||
import { openCollectionToBruno } from '@usebruno/converters';
|
||||
|
||||
const addUidsToRoot = (collection) => {
|
||||
@@ -56,6 +57,7 @@ export const processOpenCollection = async (jsonData) => {
|
||||
collection = hydrateSeqInCollection(collection);
|
||||
collection = updateUidsInCollection(collection);
|
||||
collection = addUidsToRoot(collection);
|
||||
collection = transformExampleStatusInCollection(collection);
|
||||
await validateSchema(collection);
|
||||
return collection;
|
||||
} catch (err) {
|
||||
|
||||
@@ -45,7 +45,7 @@ describe('Examples Export/Import', () => {
|
||||
}
|
||||
},
|
||||
response: {
|
||||
status: '200',
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
headers: [
|
||||
{ uid: 'res-header-1', name: 'Content-Type', value: 'application/json', enabled: true }
|
||||
@@ -67,7 +67,7 @@ describe('Examples Export/Import', () => {
|
||||
expect(httpRequest.examples[0].type).toBe('http-request');
|
||||
expect(httpRequest.examples[0].request.url).toBe('https://api.example.com/test');
|
||||
expect(httpRequest.examples[0].request.method).toBe('POST');
|
||||
expect(httpRequest.examples[0].response.status).toBe('200');
|
||||
expect(httpRequest.examples[0].response.status).toEqual(200);
|
||||
expect(httpRequest.examples[0].response.statusText).toBe('OK');
|
||||
expect(httpRequest.examples[0].response.body).toBe('{"success": true, "data": "test"}');
|
||||
});
|
||||
@@ -103,7 +103,7 @@ describe('Examples Export/Import', () => {
|
||||
body: { mode: 'none' }
|
||||
},
|
||||
response: {
|
||||
status: '200',
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
headers: [],
|
||||
body: '{"success": true}'
|
||||
@@ -123,7 +123,7 @@ describe('Examples Export/Import', () => {
|
||||
body: { mode: 'none' }
|
||||
},
|
||||
response: {
|
||||
status: '400',
|
||||
status: 400,
|
||||
statusText: 'Bad Request',
|
||||
headers: [],
|
||||
body: '{"error": "Invalid request"}'
|
||||
@@ -140,8 +140,8 @@ describe('Examples Export/Import', () => {
|
||||
expect(httpRequest.examples).toHaveLength(2);
|
||||
expect(httpRequest.examples[0].name).toBe('Success Example');
|
||||
expect(httpRequest.examples[1].name).toBe('Error Example');
|
||||
expect(httpRequest.examples[0].response.status).toBe('200');
|
||||
expect(httpRequest.examples[1].response.status).toBe('400');
|
||||
expect(httpRequest.examples[0].response.status).toEqual(200);
|
||||
expect(httpRequest.examples[1].response.status).toEqual(400);
|
||||
});
|
||||
|
||||
it('should handle examples with GraphQL requests', () => {
|
||||
@@ -191,7 +191,7 @@ describe('Examples Export/Import', () => {
|
||||
}
|
||||
},
|
||||
response: {
|
||||
status: '200',
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
headers: [
|
||||
{ uid: 'res-header-1', name: 'Content-Type', value: 'application/json', enabled: true }
|
||||
@@ -268,7 +268,7 @@ describe('Examples Export/Import', () => {
|
||||
body: { mode: 'json', json: '{}' }
|
||||
},
|
||||
response: {
|
||||
status: '200',
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
headers: [],
|
||||
body: '{"success": true}'
|
||||
@@ -281,7 +281,7 @@ describe('Examples Export/Import', () => {
|
||||
|
||||
expect(result.examples).toHaveLength(1);
|
||||
expect(result.examples[0].name).toBe('Test Example');
|
||||
expect(result.examples[0].response.status).toBe('200');
|
||||
expect(result.examples[0].response.status).toEqual(200);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -378,7 +378,7 @@ describe('Examples Export/Import', () => {
|
||||
body: { mode: 'json', json: '{}' }
|
||||
},
|
||||
response: {
|
||||
status: '200',
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
headers: [],
|
||||
body: '{"success": true}'
|
||||
@@ -430,7 +430,7 @@ describe('Examples Export/Import', () => {
|
||||
body: { mode: 'json', json: '{}' }
|
||||
},
|
||||
response: {
|
||||
status: '200',
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
headers: [],
|
||||
body: '{"success": true}'
|
||||
@@ -476,7 +476,7 @@ describe('Examples Export/Import', () => {
|
||||
body: { mode: 'json', json: '{}' }
|
||||
},
|
||||
response: {
|
||||
status: '200',
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
headers: [],
|
||||
body: '{"success": true}'
|
||||
@@ -536,7 +536,7 @@ describe('Examples Export/Import', () => {
|
||||
}
|
||||
},
|
||||
response: {
|
||||
status: '200',
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
headers: [
|
||||
{ uid: 'res-header-1', name: 'Content-Type', value: 'application/json', enabled: true }
|
||||
|
||||
41
packages/bruno-common/src/example-status/index.ts
Normal file
41
packages/bruno-common/src/example-status/index.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import each from 'lodash/each';
|
||||
import get from 'lodash/get';
|
||||
|
||||
interface Collection {
|
||||
items?: any[];
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Backward compatibility: Convert string status to number in examples
|
||||
* Old collections exported before the fix had status as string
|
||||
* This function ensures status is always a number for schema validation
|
||||
*/
|
||||
export const transformExampleStatusInCollection = (collection: Collection | Collection[]): Collection => {
|
||||
const transformItems = (items: any[] = []) => {
|
||||
each(items, (item) => {
|
||||
const examples = item.examples;
|
||||
if (examples && Array.isArray(examples)) {
|
||||
each(examples, (example) => {
|
||||
if (example.response && typeof example.response.status === 'string') {
|
||||
const statusValue = example.response.status;
|
||||
// Convert string status to number, default to null if conversion fails
|
||||
example.response.status = statusValue ? Number(statusValue) : null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (item.items && item.items.length) {
|
||||
transformItems(item.items);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
if (Array.isArray(collection)) {
|
||||
collection.forEach((col) => transformItems(col.items));
|
||||
} else {
|
||||
transformItems(collection.items);
|
||||
}
|
||||
|
||||
return collection;
|
||||
};
|
||||
@@ -2,5 +2,6 @@ export { mockDataFunctions, timeBasedDynamicVars } from './utils/faker-functions
|
||||
export { default as interpolate, interpolateObject } from './interpolate';
|
||||
export { percentageToZoomLevel } from './zoom';
|
||||
export { default as isRequestTagsIncluded } from './tags';
|
||||
export { transformExampleStatusInCollection } from './example-status';
|
||||
|
||||
export * as utils from './utils';
|
||||
|
||||
@@ -434,15 +434,18 @@ const populateRequestBody = ({ body, bodySchema, contentType }) => {
|
||||
* @param {*} params.exampleValue - The example value (object, array, or primitive)
|
||||
* @param {string} params.exampleName - Name of the example
|
||||
* @param {string} params.exampleDescription - Description of the example
|
||||
* @param {string|number} params.statusCode - HTTP status code (for response examples)
|
||||
* @param {number} params.statusCode - HTTP status code (for response examples)
|
||||
* @param {string} params.contentType - Content type (e.g., 'application/json')
|
||||
* @param {Object} [params.requestBodySchema] - Optional request body schema to populate in the example
|
||||
* @param {string} [params.requestBodyContentType] - Optional request body content type
|
||||
* @returns {Object} Bruno example object
|
||||
*/
|
||||
|
||||
const createBrunoExample = ({ brunoRequestItem, exampleValue, exampleName, exampleDescription, statusCode, contentType, requestBodySchema = null, requestBodyContentType = null }) => {
|
||||
const sanitized = String(exampleName ?? '').replace(/\r?\n/g, ' ').trim();
|
||||
const name = sanitized || `${statusCode} Response`;
|
||||
const numericStatus = Number(statusCode);
|
||||
const safeStatus = Number.isFinite(numericStatus) ? numericStatus : null;
|
||||
// Deep copy the body to avoid shared references
|
||||
const bodyCopy = {
|
||||
mode: brunoRequestItem.request.body.mode,
|
||||
@@ -468,8 +471,8 @@ const createBrunoExample = ({ brunoRequestItem, exampleValue, exampleName, examp
|
||||
body: bodyCopy
|
||||
},
|
||||
response: {
|
||||
status: String(statusCode),
|
||||
statusText: getStatusText(statusCode),
|
||||
status: safeStatus,
|
||||
statusText: safeStatus ? getStatusText(safeStatus) : null,
|
||||
headers: contentType ? [
|
||||
{
|
||||
uid: uuid(),
|
||||
@@ -803,7 +806,7 @@ const transformOpenapiRequestItem = (request, usedNames = new Set(), options = {
|
||||
* @param {*} params.responseExampleValue - The response example value
|
||||
* @param {string} params.exampleName - Name of the example
|
||||
* @param {string} params.exampleDescription - Description of the example
|
||||
* @param {string|number} params.statusCode - HTTP status code
|
||||
* @param {number} params.statusCode - HTTP status code
|
||||
* @param {string} params.responseContentType - Response content type
|
||||
* @param {string} [params.responseExampleKey] - Optional response example key for matching
|
||||
*/
|
||||
@@ -1413,9 +1416,12 @@ export const openApiToBruno = (openApiSpecification, options = {}) => {
|
||||
}
|
||||
|
||||
const collection = parseOpenApiCollection(openApiSpecification, options);
|
||||
|
||||
const transformedCollection = transformItemsInCollection(collection);
|
||||
|
||||
const hydratedCollection = hydrateSeqInCollection(transformedCollection);
|
||||
const validatedCollection = validateSchema(hydratedCollection);
|
||||
|
||||
return validatedCollection;
|
||||
} catch (err) {
|
||||
console.error('Error converting OpenAPI to Bruno:', err);
|
||||
|
||||
@@ -127,7 +127,7 @@ export const fromOpenCollectionHttpItem = (ocRequest: HttpRequest): BrunoItem =>
|
||||
body: fromOpenCollectionBody(example.request?.body) || null
|
||||
},
|
||||
response: example.response ? {
|
||||
status: String(example.response.status || 200),
|
||||
status: example.response.status || 200,
|
||||
statusText: example.response.statusText || 'OK',
|
||||
headers: fromOpenCollectionHeaders(example.response.headers as HttpRequestHeader[]) || [],
|
||||
body: example.response.body ? {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import get from 'lodash/get';
|
||||
import { validateSchema, transformItemsInCollection, hydrateSeqInCollection, uuid } from '../common';
|
||||
import { transformExampleStatusInCollection } from '@usebruno/common';
|
||||
import each from 'lodash/each';
|
||||
import postmanTranslation from './postman-translations';
|
||||
import { invalidVariableCharacterRegex } from '../constants/index';
|
||||
@@ -599,8 +600,8 @@ const importPostmanV2CollectionItem = (brunoParent, item, { useWorkers = false }
|
||||
}
|
||||
},
|
||||
response: {
|
||||
status: response.status || '',
|
||||
statusText: response.code ? response.code.toString() : '',
|
||||
status: response.code || null,
|
||||
statusText: response.status || '',
|
||||
headers: [],
|
||||
body: {
|
||||
type: getBodyTypeFromContentTypeHeader(response.header),
|
||||
@@ -905,7 +906,9 @@ const postmanToBruno = async (postmanCollection, { useWorkers = false } = {}) =>
|
||||
const parsedPostmanCollection = await parsePostmanCollection(postmanCollection, { useWorkers });
|
||||
const transformedCollection = transformItemsInCollection(parsedPostmanCollection);
|
||||
const hydratedCollection = hydrateSeqInCollection(transformedCollection);
|
||||
const validatedCollection = validateSchema(hydratedCollection);
|
||||
// Apply backward compatibility transformation for string status to number
|
||||
const statusTransformedCollection = transformExampleStatusInCollection(hydratedCollection);
|
||||
const validatedCollection = validateSchema(statusTransformedCollection);
|
||||
return validatedCollection;
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
|
||||
@@ -23,7 +23,7 @@ describe('OpenAPI with Examples', () => {
|
||||
// Check specific examples
|
||||
const successExample = getUsersRequest.examples.find((ex) => ex.name === 'Success Response');
|
||||
expect(successExample).toBeDefined();
|
||||
expect(successExample.response.status).toBe('200');
|
||||
expect(successExample.response.status).toEqual(200);
|
||||
expect(successExample.response.statusText).toBe('OK');
|
||||
expect(successExample.response.headers).toHaveLength(1);
|
||||
expect(successExample.response.headers[0].name).toBe('Content-Type');
|
||||
@@ -36,17 +36,17 @@ describe('OpenAPI with Examples', () => {
|
||||
});
|
||||
|
||||
const emptyExample = getUsersRequest.examples.find((ex) => ex.name === 'Empty Response');
|
||||
expect(emptyExample.response.status).toBe('200');
|
||||
expect(emptyExample.response.status).toEqual(200);
|
||||
expect(JSON.parse(emptyExample.response.body.content)).toEqual({ users: [] });
|
||||
|
||||
const validationErrorExample = getUsersRequest.examples.find((ex) => ex.name === 'Validation Error');
|
||||
expect(validationErrorExample).toBeDefined();
|
||||
expect(validationErrorExample.response.status).toBe('400');
|
||||
expect(validationErrorExample.response.status).toEqual(400);
|
||||
expect(validationErrorExample.response.statusText).toBe('Bad Request');
|
||||
|
||||
const serverErrorExample = getUsersRequest.examples.find((ex) => ex.name === 'Server Error');
|
||||
expect(serverErrorExample).toBeDefined();
|
||||
expect(serverErrorExample.response.status).toBe('500');
|
||||
expect(serverErrorExample.response.status).toEqual(500);
|
||||
expect(serverErrorExample.response.statusText).toBe('Internal Server Error');
|
||||
|
||||
// Test POST /users endpoint
|
||||
@@ -58,7 +58,7 @@ describe('OpenAPI with Examples', () => {
|
||||
// Check response examples
|
||||
const createdExample = createUserRequest.examples.find((ex) => ex.name === 'User Created (Valid User)');
|
||||
expect(createdExample).toBeDefined();
|
||||
expect(createdExample.response.status).toBe('201');
|
||||
expect(createdExample.response.status).toEqual(201);
|
||||
expect(createdExample.response.statusText).toBe('Created');
|
||||
expect(JSON.parse(createdExample.response.body.content)).toEqual({
|
||||
id: 123,
|
||||
@@ -418,7 +418,7 @@ paths:
|
||||
summary: 'User Created'
|
||||
value:
|
||||
id: 123
|
||||
'400':
|
||||
400:
|
||||
description: 'Bad Request'
|
||||
content:
|
||||
application/json:
|
||||
@@ -441,7 +441,7 @@ servers:
|
||||
// Check combinations for 201 response
|
||||
const createdWithValid = request.examples.find((ex) => ex.name === 'User Created (Valid User)');
|
||||
expect(createdWithValid).toBeDefined();
|
||||
expect(createdWithValid.response.status).toBe('201');
|
||||
expect(createdWithValid.response.status).toEqual(201);
|
||||
expect(JSON.parse(createdWithValid.request.body.json)).toEqual({
|
||||
name: 'John Doe',
|
||||
email: 'john@example.com'
|
||||
@@ -449,7 +449,7 @@ servers:
|
||||
|
||||
const createdWithInvalid = request.examples.find((ex) => ex.name === 'User Created (Invalid User)');
|
||||
expect(createdWithInvalid).toBeDefined();
|
||||
expect(createdWithInvalid.response.status).toBe('201');
|
||||
expect(createdWithInvalid.response.status).toEqual(201);
|
||||
expect(JSON.parse(createdWithInvalid.request.body.json)).toEqual({
|
||||
name: '',
|
||||
email: 'invalid'
|
||||
@@ -458,11 +458,11 @@ servers:
|
||||
// Check combinations for 400 response
|
||||
const errorWithValid = request.examples.find((ex) => ex.name === 'Validation Error (Valid User)');
|
||||
expect(errorWithValid).toBeDefined();
|
||||
expect(errorWithValid.response.status).toBe('400');
|
||||
expect(errorWithValid.response.status).toEqual(400);
|
||||
|
||||
const errorWithInvalid = request.examples.find((ex) => ex.name === 'Validation Error (Invalid User)');
|
||||
expect(errorWithInvalid).toBeDefined();
|
||||
expect(errorWithInvalid.response.status).toBe('400');
|
||||
expect(errorWithInvalid.response.status).toEqual(400);
|
||||
});
|
||||
|
||||
it('should use single request body example for all response examples', () => {
|
||||
@@ -781,7 +781,7 @@ paths:
|
||||
summary: 'Duplicate'
|
||||
value:
|
||||
id: 2
|
||||
'400':
|
||||
400:
|
||||
description: 'Bad Request'
|
||||
content:
|
||||
application/json:
|
||||
|
||||
@@ -120,8 +120,8 @@ describe('Postman to Bruno Converter with Examples', () => {
|
||||
expect(successExample.itemUid).toBe(request.uid);
|
||||
expect(successExample.request.url).toBe('https://testbench-sanity.usebruno.com/ping');
|
||||
expect(successExample.request.method).toBe('GET');
|
||||
expect(successExample.response.status).toBe('OK');
|
||||
expect(successExample.response.statusText).toBe('200');
|
||||
expect(successExample.response.status).toEqual(200);
|
||||
expect(successExample.response.statusText).toBe('OK');
|
||||
expect(successExample.response.body.content).toBe('{\n "ping": "pong"\n}');
|
||||
expect(successExample.response.body.type).toBe('json');
|
||||
expect(successExample.response.headers).toHaveLength(2);
|
||||
@@ -137,8 +137,8 @@ describe('Postman to Bruno Converter with Examples', () => {
|
||||
expect(errorExample.itemUid).toBe(request.uid);
|
||||
expect(errorExample.request.url).toBe('https://testbench-sanity.usebruno.com/ping');
|
||||
expect(errorExample.request.method).toBe('GET');
|
||||
expect(errorExample.response.status).toBe('Internal Server Error');
|
||||
expect(errorExample.response.statusText).toBe('500');
|
||||
expect(errorExample.response.status).toEqual(500);
|
||||
expect(errorExample.response.statusText).toBe('Internal Server Error');
|
||||
expect(errorExample.response.body.content).toBe('{\n "error": "Internal Server Error"\n}');
|
||||
expect(errorExample.response.body.type).toBe('json');
|
||||
expect(errorExample.response.headers).toHaveLength(1);
|
||||
|
||||
@@ -44,7 +44,7 @@ describe('Bruno to Postman Converter with Examples', () => {
|
||||
}
|
||||
},
|
||||
response: {
|
||||
status: '200',
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
headers: [
|
||||
{
|
||||
@@ -84,7 +84,7 @@ describe('Bruno to Postman Converter with Examples', () => {
|
||||
}
|
||||
},
|
||||
response: {
|
||||
status: '500',
|
||||
status: 500,
|
||||
statusText: 'Internal Server Error',
|
||||
headers: [
|
||||
{
|
||||
@@ -151,7 +151,7 @@ describe('Bruno to Postman Converter with Examples', () => {
|
||||
}
|
||||
},
|
||||
response: {
|
||||
status: '201',
|
||||
status: 201,
|
||||
statusText: 'Created',
|
||||
headers: [
|
||||
{
|
||||
@@ -197,7 +197,7 @@ describe('Bruno to Postman Converter with Examples', () => {
|
||||
const successResponse = getUsersRequest.response[0];
|
||||
expect(successResponse.name).toBe('Success Response');
|
||||
expect(successResponse.status).toBe('OK');
|
||||
expect(successResponse.code).toBe(200);
|
||||
expect(successResponse.code).toEqual(200);
|
||||
expect(successResponse._postman_previewlanguage).toBe('json');
|
||||
expect(successResponse.header).toHaveLength(1);
|
||||
expect(successResponse.header[0].key).toBe('Content-Type');
|
||||
@@ -239,7 +239,7 @@ describe('Bruno to Postman Converter with Examples', () => {
|
||||
const createdResponse = createUserRequest.response[0];
|
||||
expect(createdResponse.name).toBe('User Created');
|
||||
expect(createdResponse.status).toBe('Created');
|
||||
expect(createdResponse.code).toBe(201);
|
||||
expect(createdResponse.code).toEqual(201);
|
||||
expect(JSON.parse(createdResponse.body)).toEqual({
|
||||
id: 123,
|
||||
name: 'New User',
|
||||
@@ -343,7 +343,7 @@ describe('Bruno to Postman Converter with Examples', () => {
|
||||
body: { mode: 'none' }
|
||||
},
|
||||
response: {
|
||||
status: '200',
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
headers: [
|
||||
{
|
||||
@@ -369,7 +369,7 @@ describe('Bruno to Postman Converter with Examples', () => {
|
||||
body: { mode: 'none' }
|
||||
},
|
||||
response: {
|
||||
status: '200',
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
headers: [
|
||||
{
|
||||
@@ -440,7 +440,7 @@ describe('Bruno to Postman Converter with Examples', () => {
|
||||
body: { mode: 'none' }
|
||||
},
|
||||
response: {
|
||||
status: '200',
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
headers: [
|
||||
{
|
||||
|
||||
@@ -54,14 +54,14 @@ describe('transformRequestToSaveToFilesystem', () => {
|
||||
uid: 'assert-uid-1',
|
||||
name: 'Status Code',
|
||||
operator: 'equals',
|
||||
expected: '200'
|
||||
expected: 200
|
||||
}
|
||||
],
|
||||
tests: [
|
||||
{
|
||||
uid: 'test-uid-1',
|
||||
name: 'Test Response',
|
||||
code: 'expect(response.status).toBe(200);'
|
||||
code: 'expect(response.status).toEqual(200);'
|
||||
}
|
||||
],
|
||||
docs: 'This is a test request documentation'
|
||||
|
||||
@@ -171,7 +171,8 @@ const parseHttpRequest = (ocRequest: HttpRequest): BrunoItem => {
|
||||
|
||||
if (example.response) {
|
||||
brunoExample.response = {
|
||||
status: example.response.status !== undefined ? String(example.response.status) : null,
|
||||
status: typeof example.response.status === 'number' ? example.response.status
|
||||
: example.response.status !== undefined ? Number(example.response.status) : null,
|
||||
statusText: example.response.statusText || null,
|
||||
headers: toBrunoHttpHeaders(example.response.headers) || [],
|
||||
body: null
|
||||
|
||||
@@ -44,7 +44,7 @@ describe('Digest Auth with query params', () => {
|
||||
addDigestInterceptor(axiosInstance, request);
|
||||
|
||||
const res = await axiosInstance(request);
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.status).toEqual(200);
|
||||
|
||||
expect(capturedAuthorization).toBeTruthy();
|
||||
// Extract uri="..." from the header
|
||||
|
||||
@@ -17,7 +17,7 @@ export interface ExampleResponseBody {
|
||||
}
|
||||
|
||||
export interface ExampleResponse {
|
||||
status?: string | null;
|
||||
status?: number | null;
|
||||
statusText?: string | null;
|
||||
headers?: KeyValue[] | null;
|
||||
body?: ExampleResponseBody | null;
|
||||
|
||||
@@ -375,7 +375,7 @@ const exampleSchema = Yup.object({
|
||||
.strict()
|
||||
.nullable(),
|
||||
response: Yup.object({
|
||||
status: Yup.string().nullable(),
|
||||
status: Yup.number().nullable(),
|
||||
statusText: Yup.string().nullable(),
|
||||
headers: Yup.array().of(keyValueSchema).nullable(),
|
||||
body: Yup.object({
|
||||
|
||||
@@ -49,10 +49,10 @@ test.describe.serial('Create and Delete Response Examples', () => {
|
||||
await page.getByRole('button', { name: 'Create Example' }).click();
|
||||
await expect(page.getByTestId('name-error')).toBeVisible();
|
||||
await expect(page.getByTestId('name-error')).toHaveText('Example name is required');
|
||||
});
|
||||
|
||||
await test.step('Create example with valid name', async () => {
|
||||
await page.getByTestId('create-example-name-input').fill('Required Name');
|
||||
await page.getByTestId('create-example-name-input').clear();
|
||||
await page.getByTestId('create-example-name-input').fill('New Required Name');
|
||||
await expect(page.getByRole('button', { name: 'Create Example' })).toBeEnabled();
|
||||
await page.getByRole('button', { name: 'Create Example' }).click();
|
||||
|
||||
// Modal should close and example should be created
|
||||
|
||||
@@ -52,7 +52,7 @@ test.describe('CLI JSON Environment File Support', () => {
|
||||
const report = JSON.parse(fs.readFileSync(outputPath, 'utf8'));
|
||||
const result = report.results[0];
|
||||
expect(result.request.url).toBe('https://echo.usebruno.com');
|
||||
expect(result.response.status).toBe(200);
|
||||
expect(result.response.status).toEqual(200);
|
||||
|
||||
try {
|
||||
fs.unlinkSync(outputPath);
|
||||
|
||||
@@ -626,7 +626,7 @@ const selectEnvironment = async (
|
||||
*/
|
||||
const sendRequest = async (
|
||||
page: Page,
|
||||
expectedStatusCode?: number | string,
|
||||
expectedStatusCode?: number,
|
||||
timeout: number = 30000
|
||||
) => {
|
||||
await test.step('Send request', async () => {
|
||||
@@ -693,11 +693,11 @@ const openFolderRequest = async (page: Page, folderName: string, requestName: st
|
||||
/**
|
||||
* Send a request and wait for the response
|
||||
* @param page - The page object
|
||||
* @param expectedStatusCode - The expected status code (default: '200')
|
||||
* @param expectedStatusCode - The expected status code (default: 200)
|
||||
* @param options - The options for sending the request (default: { timeout: 15000 })
|
||||
*/
|
||||
const sendRequestAndWaitForResponse = async (page: Page,
|
||||
expectedStatusCode: string = '200',
|
||||
expectedStatusCode: number = 200,
|
||||
options: {
|
||||
ignoreCase?: boolean;
|
||||
timeout?: number;
|
||||
@@ -705,7 +705,7 @@ const sendRequestAndWaitForResponse = async (page: Page,
|
||||
} = { timeout: 15000 }) => {
|
||||
await test.step(`Send request and wait for status code ${expectedStatusCode}`, async () => {
|
||||
await page.getByTestId('send-arrow-icon').click();
|
||||
await expect(page.getByTestId('response-status-code')).toContainText(expectedStatusCode, options);
|
||||
await expect(page.getByTestId('response-status-code')).toContainText(String(expectedStatusCode), options);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user