Files
bruno/packages/bruno-converters/tests/postman-with-examples.spec.js
sanish chirayath 244f528277 feat(import): enhance import functionality with issue tracking and logging (#8098)
* feat: enhance import functionality with issue tracking and logging

- Updated the import process to return both collections and issues for better error handling.
- Introduced a new toast notification for displaying import issues, allowing users to copy or report them.
- Enhanced logging for import issues, capturing errors and warnings during the import process.
- Added new components for actionable toasts and import issues display.
- Updated tests to validate the new import behavior and issue tracking.

* feat: enhance import issues handling with new toast notifications and tests

- Added optional testId prop to ActionableToast for better test targeting.
- Updated ImportIssuesToast to include data-testid attributes for improved e2e testing.
- Introduced a new Postman collection fixture to test partial import scenarios.
- Created new tests to validate the import process, including issue reporting and copying functionality.
- Implemented utility functions to manage import issues toasts during tests.

* fix: improve clipboard copy functionality and handle import issues more robustly

- Updated BulkImportCollectionLocation to always set import issues, ensuring consistent state management.
- Enhanced clipboard copy functionality in ImportIssuesToast and BulkImportCollectionLocation to handle errors gracefully with user feedback.
- Added aria-label for better accessibility in ActionableToast close button.

* refactor: enhance import issue logging and toast notifications

- Improved logging in BulkImportCollectionLocation and ImportCollectionLocation to provide detailed summaries of import issues, including counts of skipped items and warnings.
- Updated ImportIssuesToast to handle long issue descriptions and provide user feedback for copying issue details to the clipboard.
- Removed ActionableToast component and its styles, consolidating toast functionality within ImportIssuesToast for better maintainability.
- Enhanced styling for ImportIssuesToast to improve user experience and accessibility.

* refactor: update logging level for import issues in BulkImportCollectionLocation and ImportCollectionLocation

- Changed log type from 'error' to 'warn' for import issue summaries in both components to better reflect the severity of the messages.
- This adjustment improves clarity in the logging system and aligns with the intended handling of import warnings.

* feat: enhance ImportIssuesToast with URL length warning and styling improvements

- Added an alert icon and improved styling for the URL-too-long warning in ImportIssuesToast to enhance user experience.
- Introduced a new test for verifying the display of the URL length warning when importing collections with many issues.
- Updated locators to include a test ID for the URL-too-long warning, facilitating better end-to-end testing.

* style: update ImportIssuesToast styling for improved user experience

- Changed background and border colors in StyledWrapper for better visual consistency.
- Enhanced box-shadow and close button styles for improved accessibility and interaction.
- Adjusted padding and gap in warning messages for better layout and readability.
2026-05-28 19:41:03 +05:30

234 lines
8.3 KiB
JavaScript

import postmanToBruno from '../src/postman/postman-to-bruno.js';
describe('Postman to Bruno Converter with Examples', () => {
const postmanCollectionWithExamples = {
info: {
_postman_id: 'd7b47cc4-c3c5-4c9d-99d4-04b6025c9000',
name: 'collection with examples',
schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json',
_exporter_id: '41238764'
},
item: [
{
name: 'New Request',
request: {
method: 'GET',
header: [],
url: {
raw: 'https://testbench-sanity.usebruno.com/ping',
protocol: 'https',
host: ['testbench-sanity', 'usebruno', 'com'],
path: ['ping']
}
},
response: [
{
name: 'Success Response',
originalRequest: {
method: 'GET',
header: [],
url: {
raw: 'https://testbench-sanity.usebruno.com/ping',
protocol: 'https',
host: ['testbench-sanity', 'usebruno', 'com'],
path: ['ping']
}
},
status: 'OK',
code: 200,
_postman_previewlanguage: 'json',
header: [
{
key: 'Content-Type',
value: 'application/json',
name: 'Content-Type',
description: '',
type: 'text'
},
{
key: 'x-powered-by',
value: 'Express'
}
],
cookie: [],
body: '{\n "ping": "pong"\n}'
},
{
name: 'Error Response',
originalRequest: {
method: 'GET',
header: [
{
key: 'Content-Type',
value: 'application/json',
type: 'text'
}
],
body: {
mode: 'raw',
raw: '{\n "ping": "pong"\n}',
options: {
raw: {
language: 'json'
}
}
},
url: {
raw: 'https://testbench-sanity.usebruno.com/ping',
protocol: 'https',
host: ['testbench-sanity', 'usebruno', 'com'],
path: ['ping']
}
},
status: 'Internal Server Error',
code: 500,
_postman_previewlanguage: 'json',
header: [
{
key: 'Content-Type',
value: 'application/json',
name: 'Content-Type',
description: '',
type: 'text'
}
],
cookie: [],
body: '{\n "error": "Internal Server Error"\n}'
}
]
}
]
};
test('should convert Postman collection with examples to Bruno format', async () => {
const { collection: brunoCollection } = await postmanToBruno(postmanCollectionWithExamples);
expect(brunoCollection).toBeDefined();
expect(brunoCollection.name).toBe('collection with examples');
expect(brunoCollection.items).toHaveLength(1);
const request = brunoCollection.items[0];
expect(request.name).toBe('New Request');
expect(request.type).toBe('http-request');
expect(request.examples).toBeDefined();
expect(request.examples).toHaveLength(2);
// Test first example (Success Response)
const successExample = request.examples[0];
expect(successExample.name).toBe('Success Response');
expect(successExample.type).toBe('http-request');
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).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);
expect(successExample.response.headers[0].name).toBe('Content-Type');
expect(successExample.response.headers[0].value).toBe('application/json');
expect(successExample.response.headers[1].name).toBe('x-powered-by');
expect(successExample.response.headers[1].value).toBe('Express');
// Test second example (Error Response)
const errorExample = request.examples[1];
expect(errorExample.name).toBe('Error Response');
expect(errorExample.type).toBe('http-request');
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).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);
expect(errorExample.response.headers[0].name).toBe('Content-Type');
expect(errorExample.response.headers[0].value).toBe('application/json');
// Test that the example has the original request headers from the originalRequest
expect(errorExample.request.headers).toHaveLength(1);
expect(errorExample.request.headers[0].name).toBe('Content-Type');
expect(errorExample.request.headers[0].value).toBe('application/json');
// Test that the example has the original request body from the originalRequest
expect(errorExample.request.body.mode).toBe('json');
expect(errorExample.request.body.json).toBe('{\n "ping": "pong"\n}');
});
test('should handle Postman collection without examples', async () => {
const postmanCollectionWithoutExamples = {
info: {
_postman_id: 'd7b47cc4-c3c5-4c9d-99d4-04b6025c9000',
name: 'collection without examples',
schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json',
_exporter_id: '41238764'
},
item: [
{
name: 'Simple Request',
request: {
method: 'GET',
header: [],
url: {
raw: 'https://api.example.com/test',
protocol: 'https',
host: ['api', 'example', 'com'],
path: ['test']
}
}
}
]
};
const { collection: brunoCollection } = await postmanToBruno(postmanCollectionWithoutExamples);
expect(brunoCollection).toBeDefined();
expect(brunoCollection.name).toBe('collection without examples');
expect(brunoCollection.items).toHaveLength(1);
const request = brunoCollection.items[0];
expect(request.name).toBe('Simple Request');
expect(request.type).toBe('http-request');
expect(request.examples).toBeUndefined();
});
test('should handle Postman collection with empty examples array', async () => {
const postmanCollectionWithEmptyExamples = {
info: {
_postman_id: 'd7b47cc4-c3c5-4c9d-99d4-04b6025c9000',
name: 'collection with empty examples',
schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json',
_exporter_id: '41238764'
},
item: [
{
name: 'Request with Empty Examples',
request: {
method: 'GET',
header: [],
url: {
raw: 'https://api.example.com/test',
protocol: 'https',
host: ['api', 'example', 'com'],
path: ['test']
}
},
response: []
}
]
};
const { collection: brunoCollection } = await postmanToBruno(postmanCollectionWithEmptyExamples);
expect(brunoCollection).toBeDefined();
expect(brunoCollection.name).toBe('collection with empty examples');
expect(brunoCollection.items).toHaveLength(1);
const request = brunoCollection.items[0];
expect(request.name).toBe('Request with Empty Examples');
expect(request.type).toBe('http-request');
expect(request.examples).toBeDefined();
expect(request.examples).toHaveLength(0);
});
});