Created
January 16, 2022 06:01
-
-
Save AkshayCHD/6a4db924bd0b9fc529a99ae2586e5f46 to your computer and use it in GitHub Desktop.
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 { saveUser } = require("../src/services/user.service"); | |
const { expect } = require("chai"); | |
const User = require("../src/models/user.model") | |
const sinon = require("sinon"); | |
describe("User Service Unit Tests", function () { | |
describe("Save User functionality", function () { | |
it("should successfully add a user if the number of users in the DB with the same profiled is zero", async function () { | |
const profileId = 1; | |
const name = "Akshay"; | |
const dob = "2020-12-12"; | |
const experience = [{ years: 2, organizationName: "ABCD" }]; | |
sinon.stub(User, "countDocuments").returns(0); | |
sinon.stub(User.prototype, "save").returns( | |
{ name, dob, experience } | |
); | |
const returnedUser = await saveUser({ | |
profileId, | |
name, | |
dob, | |
experience, | |
}); | |
expect(returnedUser.name).to.equal(name); | |
expect(returnedUser.dob).to.equal(dob); | |
experience.map((exp, index) => { | |
expect(returnedUser.experience[index].years).to.equal(exp.years); | |
expect(returnedUser.experience[index].organizationName).to.equal(exp.organizationName); | |
}) | |
}); | |
it("should throw an error if the number of users with the same profileId is not zero", async function () {}); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment