Skip to content

Commit

Permalink
PP-11681 Encode URL when making axios call (#4197)
Browse files Browse the repository at this point in the history
* PP-11681 Encode URL when making axios call

* PP-11681 Remove encoded URL pact test. Re-evaluate if needed as unit test covers testing functionality.
  • Loading branch information
JFSGDS authored Mar 26, 2024
1 parent c2c208f commit 60338b5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/services/clients/base/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function onFailureResponse (context) {
}

function configureClient (client, baseUrl) {
client.configure(baseUrl, {
client.configure(encodeURI(baseUrl), {
transformRequestAddHeaders,
onRequestStart,
onSuccessResponse,
Expand Down
30 changes: 30 additions & 0 deletions app/services/clients/base/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,34 @@ describe('Client config', () => {
})
})
})

describe('Encoding URI', () => {
it('should encode URI', async () => {
const client = new Client(app)
const config = getConfigWithMocks('abc123')
const baseUrl = 'http://localhost:8000'

nock(baseUrl)
.get('/x?y=z%20z')
.reply(200)

const url = `${baseUrl}/x?y=z z`
config.configureClient(client, url)

const response = await client.get(url, 'do something', {
additionalLoggingFields: { foo: 'bar' }
})

expect(response.status).to.equal(200)
expect(response.request.path).to.equal('/x?y=z%20z')

sinon.assert.calledWith(logInfoSpy, 'Calling an-app to do something', {
service: app,
method: 'get',
url: 'http://localhost:8000/x?y=z z',
description: 'do something',
foo: 'bar'
})
})
})
})

0 comments on commit 60338b5

Please sign in to comment.