Last active
July 23, 2019 00:56
-
-
Save EdyVision/c0f1f1bdd3b45f2bdf3f4f3c825723ec to your computer and use it in GitHub Desktop.
Drug Search Controller Test with Sinon Spy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable no-undef */ | |
/* eslint-disable no-unused-vars */ | |
const expect = require('chai').expect; | |
const sinon = require('sinon'); | |
let drugSearchCtrl = require('../../functions/drugSearch/drugSearchCtrl'); | |
let nlmSearch = require('../../functions/drugSearch/services/nlmSearch'); | |
describe('drugSearchCtrl getDrugIdentifiers', function drugSearchCtrlTest() { | |
// NLM Drug Search Service Spy | |
let nlmDrugImageSearchSpy = sinon.spy(nlmSearch, 'nlmDrugImageSearch'); | |
context('input missing - ', function() { | |
it('should return a failure', async function() { | |
let result; | |
await drugSearchCtrl | |
.getDrugIdentifiers(null) | |
.then(response => (result = response)) | |
.catch(reason => (result = reason)); | |
// Assert | |
expect(result.statusCode).to.eq(400); | |
}); | |
}); | |
context('input ok - ', function() { | |
let event = { | |
queryStringParameters: { | |
drugName: 'Albuterol' | |
} | |
}; | |
it('should return a successful search', async function() { | |
let result; | |
await drugSearchCtrl | |
.getDrugIdentifiers(event) | |
.then(response => (result = response)) | |
.catch(reason => (result = reason)); | |
// Assert | |
expect(result.statusCode).to.eq(200); | |
expect(result.body.data).to.not.eq(null); | |
nlmDrugImageSearchSpy.restore(); | |
sinon.assert.calledWith( | |
nlmDrugImageSearchSpy, | |
event.queryStringParameters.drugName | |
); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment