Skip to content

Commit

Permalink
Merge pull request #32 from atlp-rwanda/fix-swagger-doc
Browse files Browse the repository at this point in the history
fix- fixed missing req body for user login in swagger doc
  • Loading branch information
teerenzo authored and niyobertin committed Apr 29, 2024
2 parents bc4be51 + 3f45d44 commit 179c74b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 39 deletions.
17 changes: 1 addition & 16 deletions __test__/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const userData: any = {
const dummySeller = {
name: "dummy",
username: "username",
email: "srukundo02@gmail.com",
email: "niyonkurubertin50@gmail.com",
password: "1234567890",
isMerchant: true,
};
Expand Down Expand Up @@ -94,21 +94,6 @@ describe("Testing user Routes", () => {
spyonOne.mockRestore();
}, 20000);

test("Should return send magic link if seller try to login", async () => {
const spy = jest.spyOn(twoFAService, "sendOTP");
const user = {
email: dummySeller.email,
password: dummySeller.password,
};

const response = await request(app).post("/api/v1/users/login").send({
email: dummySeller.email,
password: dummySeller.password,
});

expect(response.body.message).toBe("Verification link has been sent to your email. Please verify it to continue");
}, 20000);

test("should log a user in to retrieve a token", async () => {
const response = await request(app).post("/api/v1/users/login").send({
email: userData.email,
Expand Down
57 changes: 39 additions & 18 deletions src/docs/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export const updatePasswordSchema = {
},
confirmPassword: {
type: "string",
}
}
}
},
},
};

export const loginSchema = {
properties: {
Expand Down Expand Up @@ -97,12 +97,34 @@ export const createUsers = {
export const loginAsUser = {
tags: ["Users"],
summary: "Login as user",
responses: {
200: {
description: "OK",
}
}
};
requestBody: {
required: true,
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Login",
},
},
},
},
responses: {
200: {
description: "OK",
},
400: {
description: "Bad request missing or extra filed",
},
404: {
description: "Account not found",
},
409: {
description: "Invalid credentials",
},
500: {
description: "Internal server error",
},
},
};

export const passwordUpdate = {
tags: ["Users"],
Expand All @@ -113,18 +135,17 @@ export const passwordUpdate = {
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/updatePassword"
}
}
}
$ref: "#/components/schemas/updatePassword",
},
},
},
},
responses: {
200: {
description: "OK",
},
400: {
description: "Bad Request"
}
}
}

description: "Bad Request",
},
},
};
File renamed without changes.
2 changes: 1 addition & 1 deletion src/routes/userRoutes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Router } from "express";
import { fetchAllUsers, createUserController, userLogin, updatePassword } from "../controllers/userControllers";
import { emailValidation, validateSchema } from "../middleware/validator";
import { emailValidation, validateSchema } from "../middlewares/validator";
import signUpSchema from "../schemas/signUpSchema";
import { isLoggedIn } from "../middlewares/isLoggedIn";
import { passwordUpdateSchema } from "../schemas/passwordUpdate";
Expand Down
2 changes: 1 addition & 1 deletion src/utils/2fa.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { IUser, SUBJECTS } from "../types";
import { generateMagicLinkToken, generateToken } from "../utils/jsonwebtoken";
import { env } from "../utils/env";
const verifyOtpTemplate = require("./verifyotp");
import transporter from "./transporter";
import { verifyOtpTemplate } from "./verifyotp";

export const sendOTP = async (user: IUser) => {
try {
Expand Down
4 changes: 1 addition & 3 deletions src/utils/verifyotp.js → src/utils/verifyotp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const verifyOtpTemplate = (url) => {
export const verifyOtpTemplate = (url: string) => {
return `<!DOCTYPE html>
<html lang="en">
<head>
Expand All @@ -22,5 +22,3 @@ const verifyOtpTemplate = (url) => {
</html>
`;
};

module.exports = verifyOtpTemplate;

0 comments on commit 179c74b

Please sign in to comment.