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
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