Skip to content

Commit

Permalink
Clear all users before running test
Browse files Browse the repository at this point in the history
  • Loading branch information
bzfvrto committed Jun 16, 2024
1 parent 9cb710d commit 5a3d4f6
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions __tests__/routes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ const app = require("../app");
const User = require("../models/users");
// const mongoose = require("mongoose");

// beforeEach(async () => {
// global.console = { log: jest.fn() };
// });
beforeEach(async () => {
await User.deleteMany({});
global.console = { log: jest.fn() };
});

test("it can register new user", async () => {
const response = await request(app).post("/register").send({
Expand All @@ -18,16 +19,13 @@ test("it can register new user", async () => {
});

test("it can login user", async () => {
let existingUser = await User.findOne({ email: "[email protected]" });
if (!existingUser) {
existingUser = await User({
firstname: "John",
lastname: "Doe",
email: "[email protected]",
password: "$2a$10$Qsu.gk.u76oq9Gx4uFq5F.b7JSsrx1/Vh8vROou/9ilZAnNoKniGW", // secret hashed
}).save();
}
console.log("existingUser", existingUser);
await User({
firstname: "John",
lastname: "Doe",
email: "[email protected]",
password: "$2a$10$Qsu.gk.u76oq9Gx4uFq5F.b7JSsrx1/Vh8vROou/9ilZAnNoKniGW", // secret hashed
}).save();

const response = await request(app).post("/login").send({
email: "[email protected]",
password: "secret",
Expand Down

0 comments on commit 5a3d4f6

Please sign in to comment.