Skip to content

Instantly share code, notes, and snippets.

@AkshayCHD
Created January 16, 2022 06:09
Show Gist options
  • Save AkshayCHD/5f0b00d2471e3c2aebba53579d8843c0 to your computer and use it in GitHub Desktop.
Save AkshayCHD/5f0b00d2471e3c2aebba53579d8843c0 to your computer and use it in GitHub Desktop.
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 () {
this.afterEach(() => {
sinon.restore();
})
describe("Save User functionality", function () {
it("should throw an error if the number of users with the same profileId is not 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(1)
await saveUser({
profileId,
name,
dob,
experience,
}).catch((error) => {
expect(error.message).to.equal("User with profileId already exists")
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment