Skip to content

Instantly share code, notes, and snippets.

View AkshayCHD's full-sized avatar

Akshay Kumar AkshayCHD

View GitHub Profile
const express = require("express");
const app = express();
const PORT = 5000;
app.get("/", (req, res) => {
res.json({ message: "Hello World" });
})
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();
})
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();
})
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();
})
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 { 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(
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,
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({
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 () {
});
});
});
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",