-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve how the URL values are transformed in postman export. (#3025)
* Improve how the URL values are transformed. * Made few changes and also added jsdoc comments * Removed the querystring values that are getting appended in the host array by filtering you the the queryvalues as we already have the queryparams values inside the request.params object. * Moved the transformUrl logic to a different file for testing. Added new tests. * Added tests and updated sanitizeUrl function. * Updates made in jsdocs. * Updated function params. * Review: Code restructure. * Small changes made. * Updated the return value when there is an error. * Changes
- Loading branch information
Showing
2 changed files
with
184 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
packages/bruno-app/src/utils/exporters/postman-collection.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
const { sanitizeUrl, transformUrl } = require('./postman-collection'); | ||
|
||
describe('transformUrl', () => { | ||
it('should handle basic URL with path variables', () => { | ||
const url = 'https://example.com/{{username}}/api/resource/:id'; | ||
const params = [ | ||
{ name: 'id', value: '123', type: 'path' }, | ||
]; | ||
|
||
const result = transformUrl(url, params); | ||
|
||
expect(result).toEqual({ | ||
raw: 'https://example.com/{{username}}/api/resource/:id', | ||
protocol: 'https', | ||
host: ['example', 'com'], | ||
path: ['{{username}}', 'api', 'resource', ':id'], | ||
query: [], | ||
variable: [ | ||
{ key: 'id', value: '123' }, | ||
] | ||
}); | ||
}); | ||
|
||
it('should handle URL with query parameters', () => { | ||
const url = 'https://example.com/api/resource?limit=10&offset=20'; | ||
const params = [ | ||
{ name: 'limit', value: '10', type: 'query' }, | ||
{ name: 'offset', value: '20', type: 'query' } | ||
]; | ||
|
||
const result = transformUrl(url, params); | ||
|
||
expect(result).toEqual({ | ||
raw: 'https://example.com/api/resource?limit=10&offset=20', | ||
protocol: 'https', | ||
host: ['example', 'com'], | ||
path: ['api', 'resource'], | ||
query: [ | ||
{ key: 'limit', value: '10' }, | ||
{ key: 'offset', value: '20' } | ||
], | ||
variable: [] | ||
}); | ||
}); | ||
|
||
it('should handle URL without protocol', () => { | ||
const url = 'example.com/api/resource'; | ||
const params = []; | ||
|
||
const result = transformUrl(url, params); | ||
|
||
expect(result).toEqual({ | ||
raw: 'example.com/api/resource', | ||
protocol: '', | ||
host: ['example', 'com'], | ||
path: ['api', 'resource'], | ||
query: [], | ||
variable: [] | ||
}); | ||
}); | ||
}); | ||
|
||
describe('sanitizeUrl', () => { | ||
it('should replace backslashes with slashes', () => { | ||
const input = 'http:\\\\example.com\\path\\to\\file'; | ||
const expected = 'http://example.com/path/to/file'; | ||
expect(sanitizeUrl(input)).toBe(expected); | ||
}); | ||
|
||
it('should collapse multiple slashes into a single slash', () => { | ||
const input = 'http://example.com//path///to////file'; | ||
const expected = 'http://example.com/path/to/file'; | ||
expect(sanitizeUrl(input)).toBe(expected); | ||
}); | ||
|
||
it('should handle URLs with mixed slashes', () => { | ||
const input = 'http:\\example.com//path\\to//file'; | ||
const expected = 'http://example.com/path/to/file'; | ||
expect(sanitizeUrl(input)).toBe(expected); | ||
}); | ||
}) |