mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-01 00:24:08 +00:00
Removed filtering of empty strings from url paths when importing from postman collection (#5868)
* removed filtering of empty strings from url paths when importing from postman collection * revert accidental non-pr changes * chore: remove console logs --------- Co-authored-by: Max Melhuish <238188923+max-melhuish-depop@users.noreply.github.com> Co-authored-by: Bijin A B <bijin@usebruno.com>
This commit is contained in:
committed by
GitHub
parent
575f37124c
commit
6652cca642
@@ -84,7 +84,7 @@ const constructUrlFromParts = (url) => {
|
||||
|
||||
const { protocol = 'http', host, path, port, query, hash } = url || {};
|
||||
const hostStr = Array.isArray(host) ? host.filter(Boolean).join('.') : host || '';
|
||||
const pathStr = Array.isArray(path) ? path.filter(Boolean).join('/') : path || '';
|
||||
const pathStr = Array.isArray(path) ? path.join('/') : path || '';
|
||||
const portStr = port ? `:${port}` : '';
|
||||
const queryStr
|
||||
= query && Array.isArray(query) && query.length > 0
|
||||
|
||||
@@ -79,6 +79,165 @@ describe('postman-collection', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('should successfully translate a URL path array with no empty elements', async () => {
|
||||
const collectionWithFalsyVars = {
|
||||
info: {
|
||||
_postman_id: '7f91bbd8-cb97-41ac-8d0b-e1fcd8bb4ce9',
|
||||
name: 'collection with falsy vars',
|
||||
schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json'
|
||||
},
|
||||
variable: [
|
||||
{
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
key: '',
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
value: '',
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
key: '',
|
||||
value: '',
|
||||
type: 'string'
|
||||
}
|
||||
],
|
||||
item: [
|
||||
{
|
||||
name: 'Request with all settings',
|
||||
protocolProfileBehavior: {
|
||||
maxRedirects: 10,
|
||||
followRedirects: false,
|
||||
disableUrlEncoding: true
|
||||
},
|
||||
request: {
|
||||
method: 'GET',
|
||||
header: [],
|
||||
url: {
|
||||
protocol: 'https',
|
||||
host: ['httpbin', 'org'],
|
||||
path: ['api', 'v1', 'resource']
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const brunoCollection = await postmanToBruno(collectionWithFalsyVars);
|
||||
|
||||
expect(brunoCollection.items.map((item) => item.request.url)).toEqual([
|
||||
'https://httpbin.org/api/v1/resource'
|
||||
]);
|
||||
});
|
||||
|
||||
it('should not mutate a URL path with an empty element representing a trailing slash', async () => {
|
||||
const collectionWithFalsyVars = {
|
||||
info: {
|
||||
_postman_id: '7f91bbd8-cb97-41ac-8d0b-e1fcd8bb4ce9',
|
||||
name: 'collection with falsy vars',
|
||||
schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json'
|
||||
},
|
||||
variable: [
|
||||
{
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
key: '',
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
value: '',
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
key: '',
|
||||
value: '',
|
||||
type: 'string'
|
||||
}
|
||||
],
|
||||
item: [
|
||||
{
|
||||
name: 'Request with all settings',
|
||||
protocolProfileBehavior: {
|
||||
maxRedirects: 10,
|
||||
followRedirects: false,
|
||||
disableUrlEncoding: true
|
||||
},
|
||||
request: {
|
||||
method: 'GET',
|
||||
header: [],
|
||||
url: {
|
||||
protocol: 'https',
|
||||
host: ['httpbin', 'org'],
|
||||
path: ['api', 'v1', 'resource', '']
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const brunoCollection = await postmanToBruno(collectionWithFalsyVars);
|
||||
|
||||
expect(brunoCollection.items.map((item) => item.request.url)).toEqual([
|
||||
'https://httpbin.org/api/v1/resource/'
|
||||
]);
|
||||
});
|
||||
|
||||
it('should not mutate a URL path with an empty element representing a trailing slash', async () => {
|
||||
const collectionWithFalsyVars = {
|
||||
info: {
|
||||
_postman_id: '7f91bbd8-cb97-41ac-8d0b-e1fcd8bb4ce9',
|
||||
name: 'collection with falsy vars',
|
||||
schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json'
|
||||
},
|
||||
variable: [
|
||||
{
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
key: '',
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
value: '',
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
key: '',
|
||||
value: '',
|
||||
type: 'string'
|
||||
}
|
||||
],
|
||||
item: [
|
||||
{
|
||||
name: 'Request with all settings',
|
||||
protocolProfileBehavior: {
|
||||
maxRedirects: 10,
|
||||
followRedirects: false,
|
||||
disableUrlEncoding: true
|
||||
},
|
||||
request: {
|
||||
method: 'GET',
|
||||
header: [],
|
||||
url: {
|
||||
protocol: 'https',
|
||||
host: ['httpbin', 'org'],
|
||||
path: ['api', '', 'resource']
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const brunoCollection = await postmanToBruno(collectionWithFalsyVars);
|
||||
|
||||
expect(brunoCollection.items.map((item) => item.request.url)).toEqual([
|
||||
'https://httpbin.org/api//resource'
|
||||
]);
|
||||
});
|
||||
|
||||
it('should handle empty variables', async () => {
|
||||
const collectionWithEmptyVars = {
|
||||
info: {
|
||||
|
||||
Reference in New Issue
Block a user