@ministryofjustice/fb-jwt-client-node
Advanced tools
Comparing version 0.0.23-a to 0.0.23-b
@@ -356,3 +356,3 @@ const prometheus = require('prom-client') | ||
statusMessage, | ||
body: body, | ||
body, | ||
retryCount | ||
@@ -363,2 +363,3 @@ } | ||
requestMetricsEnd(getResponseLabels(response)) | ||
response.body = response.body || '{}' | ||
return response | ||
@@ -377,3 +378,2 @@ } | ||
} catch (error) { | ||
console.log('error.response.body', error.response.body) | ||
apiMetricsEnd(getResponseLabels(error)) | ||
@@ -380,0 +380,0 @@ if (logger) { |
@@ -376,37 +376,2 @@ const test = require('tape') | ||
const getNockedResponse = (url, response, code = 201) => { | ||
const serviceUrl = 'http://testdomain' | ||
const nockedClient = new FBJWTClient(serviceSecret, serviceToken, serviceSlug, serviceUrl) | ||
nock(serviceUrl) | ||
.get(url) | ||
.reply(code, response) | ||
return nockedClient.send('get', {url}) | ||
} | ||
test('When calling an endpoint that returns json as it body', async t => { | ||
const response = await getNockedResponse('/json-body', {success: true}) | ||
t.deepEqual(response, {success: true}, 'it should return the body') | ||
t.end() | ||
}) | ||
test('When calling an endpoint that returns empty json as it body', async t => { | ||
const response = await getNockedResponse('/empty-json-body', {}) | ||
t.deepEqual(response, {}, 'it should return the body') | ||
t.end() | ||
}) | ||
test('When calling an endpoint that returns an empty string as it body', async t => { | ||
const response = await getNockedResponse('/empty-string-body', {}) | ||
t.deepEqual(response, {}, 'it should return an empty json object') | ||
t.end() | ||
}) | ||
test('When calling an endpoint that returns an empty string as it body', async t => { | ||
const response = await getNockedResponse('/undefined-body', {}) | ||
t.deepEqual(response, {}, 'it should return an empty json object') | ||
t.end() | ||
}) | ||
test('When retrying an endpoint', async t => { | ||
@@ -467,2 +432,37 @@ const retryClient = new FBJWTClient(serviceSecret, serviceToken, serviceSlug, 'http://testdomain') | ||
const getNockedResponse = (url, response, code = 201) => { | ||
const serviceUrl = 'http://testdomain' | ||
const nockedClient = new FBJWTClient(serviceSecret, serviceToken, serviceSlug, serviceUrl) | ||
nock(serviceUrl) | ||
.get(url) | ||
.reply(code, response) | ||
return nockedClient.send('get', {url}) | ||
} | ||
test('When calling an endpoint that returns json as it body', async t => { | ||
const response = await getNockedResponse('/json-body', {success: true}) | ||
t.deepEqual(response, {success: true}, 'it should return the body') | ||
t.end() | ||
}) | ||
test('When calling an endpoint that returns empty json as it body', async t => { | ||
const response = await getNockedResponse('/empty-json-body', {}) | ||
t.deepEqual(response, {}, 'it should return the body') | ||
t.end() | ||
}) | ||
test('When calling an endpoint that returns an empty string as it body', async t => { | ||
const response = await getNockedResponse('/empty-string-body', '') | ||
t.deepEqual(response, {}, 'it should return an empty json object') | ||
t.end() | ||
}) | ||
test('When calling an endpoint that returns an empty string as it body', async t => { | ||
const response = await getNockedResponse('/undefined-body') | ||
t.deepEqual(response, {}, 'it should return an empty json object') | ||
t.end() | ||
}) | ||
/** | ||
@@ -469,0 +469,0 @@ * Convenience function for testing client error handling |
{ | ||
"name": "@ministryofjustice/fb-jwt-client-node", | ||
"version": "0.0.23-a", | ||
"version": "0.0.23-b", | ||
"description": "Form Builder JSON Web Token Client (Node)", | ||
@@ -5,0 +5,0 @@ "main": "lib/fb-jwt-client.js", |
55075