I am trying to get my unit tests to pass/fail based on their response code. I am trying to pass a variable statusCode to equal the result of the function callback but the value is only temporary since it is enclosed within the function. I have tried letting statusCode = callback() but I need to pass in the parameters of the function. I don't know what other steps to take, any help would be greatly appreciated.
let statusCode;
it('should be able to get all certificates', async () => {
const request = require('request');
const headers = {
accept: 'application/json',
Authorization: ('Bearer ' + Authorization),
signature: Signature,
};
const options = {
url: url + '/v3/certificates',
headers: headers,
};
function callback(error, response, body) {
if (!error) {
console.log("Certificates: " + body);
}
statusCode = response.statusCode;
console.log("Code : " + statusCode);
return response.statusCode;
}
request(options, callback);
console.log("Code 2 : " + statusCode);
console.debug(assert.equal(statusCode, 200));
});