Skip to content

Instantly share code, notes, and snippets.

@EdyVision
Last active July 23, 2019 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EdyVision/c0f1f1bdd3b45f2bdf3f4f3c825723ec to your computer and use it in GitHub Desktop.
Save EdyVision/c0f1f1bdd3b45f2bdf3f4f3c825723ec to your computer and use it in GitHub Desktop.
Drug Search Controller Test with Sinon Spy
/* 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