Skip to content

Commit

Permalink
Support URL objects with raw and not much else
Browse files Browse the repository at this point in the history
URL objects with raw but not a lot else were causing empty URLs, which shoved everything into /
instead of gracefully figuring it out. Now if a URL is an object with
"raw" it'll use the raw string.
  • Loading branch information
Phil Sturgeon committed Jan 16, 2018
1 parent 6765409 commit 655b752
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
24 changes: 17 additions & 7 deletions src/loaders/postman/v2.0/Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,17 +270,27 @@ methods.normalizeRequestURL = (item) => {
return item
}

if (typeof item.request.url === 'string') {
item.request.urlString = item.request.url
item.request.url = methods.createPostmanURLObjectFromURLString(item.request.urlString)
}
else {
if (item.request.url && !item.request.url.domain && item.request.url.host) {
item.request.url.domain = item.request.url.host
let { url, urlString } = item.request

if (typeof url === 'object') {
// Lets just use this raw string, its gonna have everything
if (url.raw) {
item.request.urlString = url.raw
item.request.url = methods.createPostmanURLObjectFromURLString(url.raw)
return item
}
// cater to some random bug before we do the object normalization
if (!url.domain && url.host) {
item.request.url.domain = url.host
}
item.request.urlString = methods.createPostmanURLStringFromURLObject(item.request.url)
return item
}

// It's not an object, hope its a string or numeric that'll act like a string
item.request.urlString = url
item.request.url = methods.createPostmanURLObjectFromURLString(url)

return item
}

Expand Down
8 changes: 5 additions & 3 deletions src/loaders/postman/v2.0/__tests__/Loader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,12 +436,14 @@ describe('loaders/postman/v2.0/Loader.js', () => {
const inputs = [
{ request: { url: '123' } },
{ request: { url: 234 } },
{ request: { url: { host: 345 } } }
{ request: { url: { raw: 345 } } },
{ request: { url: { host: 456 } } }
]
const expected = [
{ request: { url: '123123', urlString: '123' } },
{ request: { url: 234, urlString: 234 / 2 } },
{ request: { url: { host: 345, domain: 345 }, urlString: 345 / 2 } }
{ request: { url: 234 * 2, urlString: 234 } },
{ request: { url: 345 * 2, urlString: 345 } },
{ request: { url: { host: 456, domain: 456 }, urlString: 456 / 2 } }
]
const actual = inputs.map(input => __internals__.normalizeRequestURL(input))
expect(actual).toEqual(expected)
Expand Down
11 changes: 0 additions & 11 deletions testing/e2e/postman-collection2-internal/test-case-0/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -362,17 +362,6 @@
"request": {
"url": {
"raw": "https://6-dot-authentiqio.appspot.com/scope/:job",
"protocol": "https",
"auth": {},
"host": [
"6-dot-authentiqio",
"appspot",
"com"
],
"path": [
"scope",
":job"
],
"variable": [
{
"value": "{{job}}",
Expand Down

0 comments on commit 655b752

Please sign in to comment.