Skip to content

Commit

Permalink
fix: update
Browse files Browse the repository at this point in the history
  • Loading branch information
davidebianchi committed May 10, 2022
1 parent c2e6b9c commit 063d4c2
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/httpClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class HttpClient {
})
}

// TODO: add test
getLogger(options) {
return options.logger || this.baseOptions.logger || Pino({ level: 'silent' })
}
Expand Down
54 changes: 54 additions & 0 deletions tests/httpClient.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1782,6 +1782,60 @@ tap.test('httpClient', test => {
myServiceNameScope.done()
})

innerTest.test('log correctly - options overwrite base options', async assert => {
const stream = split(JSON.parse)
const pino = Pino({ level: 'trace' }, stream)

stream.once('data', beforeRequest => {
assert.match(beforeRequest, {
level: 10,
msg: /^make call$/,
url: new RegExp(`^${MY_AWESOME_SERVICE_PROXY_HTTP_URL}/foo$`),
time: /[0-9]+/,
headers: {
some: 'value',
},
payload: {
request: 'body',
},
})

stream.once('data', afterRequest => {
assert.match(afterRequest, {
level: 10,
msg: /^response info$/,
statusCode: 200,
headers: {
some: 'response-header',
},
payload: { the: 'response' },
})
})
})

const myServiceNameScope = nock(MY_AWESOME_SERVICE_PROXY_HTTP_URL)
.replyContentLength()
.post('/foo')
.reply(200, { the: 'response' }, {
some: 'response-header',
})
const httpClient = new HttpClient(MY_AWESOME_SERVICE_PROXY_HTTP_URL, {}, {
logger: Pino({ level: 'trace' }),
})
const response = await httpClient.post('/foo', {
request: 'body',
}, {
headers: {
some: 'value',
},
logger: pino,
})

assert.equal(response.statusCode, 200)

myServiceNameScope.done()
})

innerTest.test('log correctly - response error', async assert => {
const stream = split(JSON.parse)
const pino = Pino({ level: 'trace' }, stream)
Expand Down

0 comments on commit 063d4c2

Please sign in to comment.