I recently started writing unit tests, and started to move onto integration tests. I have this rather simple method, but I am a bit lost on how to approach or even how exactly to test this.
list (token, cb) {
const requestArgs = {
headers: { 'Authorization': `Bearer ${token}` },
method: 'GET',
uri: `${BASE_URL}/rest/V1/modules`,
json: true
}
request(requestArgs, (err, msg, resp) => {
if (err) {
return cb(err) // library error
}
return cb(null, resp)
})
}
From reading various articles and the Sinon documentation, it sounds like I might possibly need a "spy" or a "mock" for request()
? Even if I faked the external API call with a good response, what good does it do if it always returns a good response since all this method does is put together requestArgs
and return the external call's response. I'm confused with the terms "stub", "spy", and "mock" and what I need to do for this wrapper method.