Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: overwriteRequestBaseUrl - overwrite value with path parameters excludes parameters #446

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"faker": "^5.5.3",
"fp-ts": "^2.12.3",
"fs-extra": "^10.1.0",
"lodash": "^4.17.21",
"newman": "^5.3.2",
"node-emoji": "^1.11.0",
"openapi-format": "^1.13.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,43 @@ Object {
}
`;

exports[`overwriteRequestBaseUrl should overwrite the request base url with a variable and path 1`] = `
Object {
"host": Array [
"{{foo-bar-baz}}",
],
"path": Array [
"path",
"crm",
"companies",
":id",
],
"query": Array [
Object {
"description": Object {
"content": "Include raw response. Mostly used for debugging purposes",
"type": "text/plain",
},
"disabled": false,
"key": "raw",
"value": "true",
},
],
"variable": Array [
Object {
"description": Object {
"content": "(Required) ID of the record you are acting upon.",
"type": "text/plain",
},
"disabled": false,
"key": "id",
"type": "any",
"value": "123456",
},
],
}
`;

exports[`overwriteRequestBaseUrl should remove the request base url when remove is true 1`] = `
Object {
"path": Array [
Expand Down
16 changes: 16 additions & 0 deletions src/application/overwrites/overwriteRequestBaseUrl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,20 @@ describe('overwriteRequestBaseUrl', () => {
expect(result.item.request.url.getHost()).toBe('')
expect(result.item.request.url).toMatchSnapshot()
})

it('should overwrite the request base url with a variable and path', async () => {
const overwriteValue = {
value: '{{foo-bar-baz}}/path'
}

const pmOperation = await getPostmanMappedOperation()
const result = overwriteRequestBaseUrl(overwriteValue, pmOperation)
expect(result.item.request.url.getHost()).toBe('{{foo-bar-baz}}')
expect(result.item.request.url.path).toBeDefined()
expect(result.item.request.url.path?.length).toEqual(4)
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
expect(result.item.request.url.path[0]).toEqual('path')
expect(result.item.request.url).toMatchSnapshot()
})
})
10 changes: 9 additions & 1 deletion src/application/overwrites/overwriteRequestBaseUrl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PostmanMappedOperation } from '../../postman'
import { OverwriteRequestBaseUrlConfig } from '../../types'
import { isEqual } from 'lodash'
// import { Header } from 'postman-collection'

/**
Expand Down Expand Up @@ -31,10 +32,17 @@ export const overwriteRequestBaseUrl = (
newPm.item.request.url.update('')
}

// Update protocol, host & port
// Update protocol, host, port & path
pmOperation.item.request.url.protocol = newPm.item.request.url.protocol
pmOperation.item.request.url.port = newPm.item.request.url.port
pmOperation.item.request.url.host = newPm.item.request.url.host
// if they are equal then no path was provided in the overwrite value
if (!isEqual(pmOperation.item.request.url.path, newPm.item.request.url.path)) {
pmOperation.item.request.url.path = [
...(newPm.item.request.url.path ?? []),
...(pmOperation.item.request.url.path ?? [])
]
}

return pmOperation
}