Skip to content

Commit

Permalink
fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
YvetteNyibuka committed Apr 29, 2024
1 parent dd9168a commit 5678f04
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
9 changes: 4 additions & 5 deletions src/__test__/users.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("USER API TEST", () => {
expect(body.message).toStrictEqual(
"Account Created successfully, Plase Verify your Account",
);

const tokenRecord = await Token.findOne();
token = tokenRecord?.dataValues.token ?? "";
});
Expand All @@ -70,7 +70,7 @@ describe("USER API TEST", () => {
expect(body.status).toStrictEqual("CONFLICT");
expect(body.message).toStrictEqual("User already exist!");
});

// it("should verify a user's account and return 200", async () => {
// // Assuming you have a way to create a user and a corresponding verification token

Expand Down Expand Up @@ -145,10 +145,9 @@ describe("USER API TEST", () => {
const { body } = await Jest_request.post("/api/v1/users/forgot-password")
.send(requestResetBody)
.expect(200);
resetToken = body.data.resetToken;
resetToken = body.data.resetToken;
expect(body.status).toStrictEqual("SUCCESS");
expect(body.message).toStrictEqual("Email sent successfully");

});

it("it should return 404 when user requesting reset is not found in database", async () => {
Expand All @@ -175,7 +174,7 @@ describe("USER API TEST", () => {
.send(newPasswordBody)
.expect(200);
});

it("it should return 400 when invalid link is provided", async () => {
const { body } = await Jest_request.post(
`/api/v1/users/reset-password/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjRmYmM3NzM4LWE5YWItNDc2MC1hYzIxLWUzNTZkNGY0NDZjNyIsImVtYWlsIjoiaXphbnlpYnVrYXl2ZXR0ZTEwNUBnbWFpbC5jb20iLCJpYXQiOjE3MTQwNzcxOTksImV4cCI6MTcxNDE2MzU5OX0.wwtJXaviKcQYqmVX0LI0Yw1jG0wmBSqW4rHZA0Vh8zk`,
Expand Down
1 change: 0 additions & 1 deletion src/controllers/resetPasswort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export const forgotPassword = async (req: Request, res: Response) => {

export const resetPasswort = async (req: Request, res: Response) => {
try {

const { password } = req.body;
const { token } = req.params;

Expand Down
1 change: 0 additions & 1 deletion src/controllers/userController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ const accountVerify = async (req: Request, res: Response) => {
return res.status(400).json({ status: 400, message: "Invalid link" });
}


const { user } = validateToken(token.dataValues.token, JWT_SECRET || "");
if (!user) {
return res.status(400).json({ status: 400, message: "Invalid link" });
Expand Down
12 changes: 10 additions & 2 deletions src/routes/userRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,16 @@ userRoutes.post(
userRoutes.post("/login", userMiddleware.logInValidated, userController.login);

userRoutes.post("/logout", logout);
userRoutes.post("/forgot-password", userMiddleware.resetValidated, forgotPassword);
userRoutes.post("/reset-password/:token",userMiddleware.isPassword, resetPasswort);
userRoutes.post(
"/forgot-password",
userMiddleware.resetValidated,
forgotPassword,
);
userRoutes.post(
"/reset-password/:token",
userMiddleware.isPassword,
resetPasswort,
);
userRoutes.get("/account/verify/:token", userController.accountVerify);

export default userRoutes;
4 changes: 2 additions & 2 deletions src/validations/newPassword.validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import Joi from "joi";

const newPasswordValidation = Joi.object({
password: Joi.string().required().messages({
"string.empty": "Password field can't be empty!"
})
"string.empty": "Password field can't be empty!",
}),
}).options({ allowUnknown: true });

const validateNewPassword = (body: any) => {
Expand Down
2 changes: 1 addition & 1 deletion src/validations/reset.validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const ResetPasswordValidation = Joi.object({
email: Joi.string().required().email().messages({
"string.empty": "Email field can not be empty!",
"string.email": "Invalid email!",
})
}),
}).options({ allowUnknown: true });

const validateReset = (body: any) => {
Expand Down

0 comments on commit 5678f04

Please sign in to comment.