Created
January 16, 2022 06:09
-
-
Save AkshayCHD/5f0b00d2471e3c2aebba53579d8843c0 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 () { | |
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