Skip to content

Instantly share code, notes, and snippets.

@rezaindrag
Last active July 3, 2020 17:13
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 rezaindrag/0962b5fe2cd01b9f2797e487c704b65b to your computer and use it in GitHub Desktop.
Save rezaindrag/0962b5fe2cd01b9f2797e487c704b65b to your computer and use it in GitHub Desktop.
const expect = require("chai").expect;
const { spy, stub } = require("sinon");
const companyService = require("../src/services/company.service");
const companyHandler = require("../src/handlers/company.handler");
const companyProfileMock = {
companyName: 'Facebook Inc',
companyUsers: [
{ id: 1, name: 'mojombo' },
{ id: 2, name: 'defunkt' },
],
companyEmployees: [
{ id: 1, name: 'Tiger Nixon' },
{ id: 2, name: 'Garrett Winters' },
],
};
describe("test company handler", function () {
afterEach(() => {
// This is required to clean up the fetchCompanyProfile mock
// after each test. The goal is that the next testing is not
// be affected or disturbed by the previous mock.
companyService.fetchCompanyProfile.restore();
});
it("should succeed", async function () {
const fetchCompanyProfileFn = stub(companyService, "fetchCompanyProfile")
.returns(companyProfileMock);
const req = {};
const res = {
json: spy(),
};
await companyHandler.fetchCompanyProfile(req, res);
expect(fetchCompanyProfileFn.calledOnce).to.be.true;
expect(res.json.calledOnce).to.be.true;
expect(res.json.firstCall.args[0]).to.deep.equal(companyProfileMock);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment