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 express = require("express"); | |
const app = express(); | |
const PORT = 5000; | |
app.get("/", (req, res) => { | |
res.json({ message: "Hello World" }); | |
}) |
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, getUser } = 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(); | |
}) |
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 { getUser, 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(); | |
}) |
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(); | |
}) |
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; |
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 mongoose = require("mongoose"); | |
const username = "root"; | |
const password = "example"; | |
const dbname = "mongo-sinon"; | |
mongoose.connect( |
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 mongoose = require("mongoose"); | |
const username = "root"; | |
const password = "example"; | |
const dbname = "mongo-sinon"; | |
mongoose.connect( | |
`mongodb://${username}:${password}@localhost:27017/${dbname}?authSource=admin&readPreference=primary`, | |
{ | |
useNewUrlParser: true, | |
useUnifiedTopology: true, |
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"); | |
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" }]; | |
const returnedUser = await saveUser({ |
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
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 () { | |
}); | |
it("should throw an error if the number of users with the same profileId is not zero", async function () { | |
}); | |
}); | |
}); |
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 express = require("express"); | |
const app = express(); | |
// Post API to add user to Database | |
app.post("/", async (req, res, next) => { | |
try { | |
const { profileId, name, dob, experience } = req.body; | |
const user = await saveUser({ profileId, name, dob, experience }); | |
res.json({ | |
message: "Inserted Successfully", |
NewerOlder