Skip to content

Commit

Permalink
Merge pull request #70 from atlp-rwanda/ft--email-mock
Browse files Browse the repository at this point in the history
mocked all email service calling during the test
  • Loading branch information
teerenzo authored May 28, 2024
2 parents 9b8d8e4 + be845b7 commit d6670df
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
5 changes: 5 additions & 0 deletions __test__/cart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import { dummy } from "./prod";
import * as userServices from "../src/services/user.service"
import { number } from "joi";

jest.mock("../src/services/mail.service", () => ({
sendEmailService: jest.fn(),
sendNotification: jest.fn(),
}));

const queryInterface = sequelize.getQueryInterface();

let sellerToken: any;
Expand Down
6 changes: 6 additions & 0 deletions __test__/payment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ let adminToken: any;
let sellerToken: any;


jest.mock("../src/services/mail.service", () => ({
sendEmailService: jest.fn(),
sendNotification: jest.fn(),
}));


describe("test stripe api payment", () => {
beforeAll(async () => {
try {
Expand Down
5 changes: 5 additions & 0 deletions __test__/product.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import CartItem from "../src/sequelize/models/CartItem";
import OrderItem from "../src/sequelize/models/orderItems";
import * as userService from "../src/services/user.service"

jest.mock("../src/services/mail.service", () => ({
sendEmailService: jest.fn(),
sendNotification: jest.fn(),
}));

const userData: any = {
name: "yvanna",
username: "testuser",
Expand Down
21 changes: 16 additions & 5 deletions __test__/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ import Redis from "ioredis";
import { env } from "../src/utils/env";
import { generateResetToken } from "../src/utils/generateResetToken";

let redisClient:any;
let redisClient: any;

jest.mock("../src/services/mail.service", () => ({
sendEmailService: jest.fn(),
sendNotification: jest.fn(),
}));


const userData: any = {
Expand All @@ -32,7 +37,7 @@ const userData: any = {
const dummySeller = {
name: "dummy1234",
username: "username1234",
email: "soleilcyber00@gmail.com",
email: "srukundo01@gmail.com",
password: "1234567890",
lastPasswordUpdateTime: "3000, 11, 18"
};
Expand Down Expand Up @@ -233,15 +238,21 @@ describe("Testing user Routes", () => {

});

test("Should send otp verification code", async () => {
test("Should send otp verification code", async () => {
jest.unmock("../src/services/mail.service");
const originalMailService = jest.requireActual("../src/services/mail.service");
const spy = jest.spyOn(mailServices, "sendEmailService");
const response = await request(app).post("/api/v1/users/login").send({
email: dummySeller.email,
password: dummySeller.password,
});

expect(response.body.message).toBe("OTP verification code has been sent ,please use it to verify that it was you");
// expect(spy).toHaveBeenCalled();
expect(response.body.message).toBe("OTP verification code has been sent ,please use it to verify that it was you");
expect(spy).toHaveBeenCalled()
jest.mock("../src/services/mail.service", () => ({
sendEmailService: jest.fn(),
sendNotification: jest.fn(),
}));
}, 70000);

test("should log a user in to retrieve a token", async () => {
Expand Down

0 comments on commit d6670df

Please sign in to comment.