Skip to content

Commit

Permalink
feat(GitHub Action): Update node.js.yml
Browse files Browse the repository at this point in the history
- Added "migrate undo" and "migrate" commands to the test process.
[Finishes #187419056]
  • Loading branch information
Hakizimana-Clement committed Apr 29, 2024
1 parent 2258cf4 commit 45dddc2
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 42 deletions.
15 changes: 9 additions & 6 deletions .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ ACCESS_TOKEN_SECRET= < Your ACCESS_TOKEN_SECRET >
GOOGLE_CLIENT_ID=
GOOGLE_SECRET_ID=
GOOGLE_CALLBACK_URL=
SESSION_SECRET=

ACCESS_TOKEN_SECRET=
SENDER_NAME=
EMAIL=
PASSWORD=
ACCESS_TOKEN_SECRET=
SENDGRID_API_KEY=<YOUR_GRID_API_KEY>
SENDGRID_API_KEY=<YOUR_GRID_API_KEY>

BASE_URL = < your BASE_URL>
HOST = < your Host >
SERVICE = < your SERVICE >

EMAIL=<your email>
PASSWORD=<email password>

4 changes: 0 additions & 4 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ jobs:
CLOUDINARY_API_SECRET: ${{ secrets.CLOUDINARY_API_SECRET }}
CLOUDINARY_FOLDER_NAME: ${{ secrets.CLOUDINARY_FOLDER_NAME }}

GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
GOOGLE_SECRET_ID: ${{ secrets.GOOGLE_SECRET_ID }}
GOOGLE_CALLBACK_URL: ${{ secrets.GOOGLE_CALLBACK_URL }}

strategy:
matrix:
node-version: ["20.x"]
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
"check": "prettier . --check",
"prepare": "husky",
"precommit": "prettier . --write && eslint --fix .",
"run-tests": "cross-env NODE_ENV=test jest --coverage --verbose --testTimeout=10000",
"run-tests": "cross-env NODE_ENV=test jest --detectOpenHandles --coverage --verbose --testTimeout=10000",
"pretest": "cross-env NODE_ENV=test npm run migrate:reset",
"run-after-tests": "cross-env NODE_ENV=test sequelize db:migrate:undo:all",
"test": "npm-run-all run-tests run-after-tests --continue-on-error"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@sendgrid/mail": "^8.1.3",
Expand Down Expand Up @@ -64,10 +63,13 @@
"coveragePathIgnorePatterns": [
"/src/services/mailService.ts",
"/src/middlewares/passport.ts",
"/src/middlewares/auth.ts",
"/src/database/config/config.js",
"/src/database/config/db.config.ts",
"/src/utils",
"src/helpers",
"src/documention/index.ts"
"src/documention/index.ts",
"/src/helpers/security.helpers.ts"
]
},
"devDependencies": {
Expand Down
13 changes: 1 addition & 12 deletions src/__test__/google.auth.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import app from "../app";
import request from "supertest";
import { connectionToDatabase } from "../database/config/db.config";
import { deleteTableData } from "../utils/database.utils";
import { User } from "../database/models/User";
import { google_profile } from "../mock/static";
jest.setTimeout(30000);

Expand All @@ -19,14 +16,6 @@ function logErrors(
const Jest_request = request(app.use(logErrors));

describe("GOOGLE API TEST", () => {
beforeAll(async () => {
await connectionToDatabase();
});

afterAll(async () => {
await deleteTableData(User, "users");
});

it("should simulate Google oAuth flow and return 302", async () => {
const response = await Jest_request.get("/api/v1/users/auth/google").expect(
302,
Expand All @@ -38,7 +27,7 @@ describe("GOOGLE API TEST", () => {
expect(response.header["set-cookie"]).toBeDefined();
});

it("should handle google oauth callback and display user data to log in or to create user", async () => {
it("should handle google oauth callback and display direct link", async () => {
const response = await Jest_request.get(
"/api/v1/users/auth/google/callback",
).query(google_profile);
Expand Down
6 changes: 4 additions & 2 deletions src/controllers/userController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,13 @@ const accountVerify = async (req: Request, res: Response) => {
.json({ status: 400, message: "Something went wrong", error: error });
}
};
const googleAuthInit = async (req: Request, res: Response) => {

export const googleAuthInit = async (req: Request, res: Response) => {
passport.authenticate("google", { scope: ["profile", "email"] });
res.redirect("/api/v1/users/auth/google/callback");
};

const handleGoogleAuth = async (
export const handleGoogleAuth = async (
req: Request,
res: Response,
next: NextFunction,
Expand All @@ -191,6 +192,7 @@ const handleGoogleAuth = async (
).response();
return res.status(200).json({ ...response, token });
}

const newUser = await User.create({ ...userData });
await newUser.save();
const token = generateAccessToken({
Expand Down
1 change: 0 additions & 1 deletion src/database/config/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require("dotenv").config();

//add ssl in this config
process.env.DB_HOSTED_MODE == "local"
? (dialect_option = {})
: (dialect_option = {
Expand Down
4 changes: 2 additions & 2 deletions src/database/config/db.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const dialect_option = isLocal
? {}
: {
ssl: {
require: true,
rejectUnauthorized: false,
require: process.env.SSL,
rejectUnauthorized: true,
},
};

Expand Down
6 changes: 0 additions & 6 deletions src/database/migrations/20240419093334-create_users_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ module.exports = {
allowNull: false,
type: Sequelize.DATE,
},

isVerified: {
type: Sequelize.BOOLEAN,
allowNull: false,
defaultValue: false,
},
});
},

Expand Down
2 changes: 1 addition & 1 deletion src/documention/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ const reset2_FA = {
responses,
},
Twofa: {
tags: ["Users"],
tags: ["User"],

security: [
{
Expand Down
7 changes: 3 additions & 4 deletions src/middlewares/passport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ passport.use(
const user = await User.findOne({ where: { email } });

if (!user) return done(null, false, { message: "Wrong credentials!" });
if (!user.dataValues.isVerified) {
return done(null, false, { message: "Verify your Account" });
}

const currPassword = user.dataValues.password;

Expand All @@ -87,6 +84,9 @@ passport.use(
return done(null, false, { message: "Wrong credentials!" });
}

if (!user.dataValues.isVerified) {
return done(null, false, { message: "Verify your Account" });
}
return done(null, user);
} catch (error) {
done(error);
Expand All @@ -101,7 +101,6 @@ interface GoogleProfileData {
familyName: string;
};
emails: Array<{ value: string }>;
photos: Array<{ value: string }>;
}
const userProfile = (profile: GoogleProfileData): UserModelAttributes => {
const { name, emails } = profile;
Expand Down
2 changes: 1 addition & 1 deletion src/mock/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const bad_two_factor_authentication_data = {

export const partial_two_factor_authentication_data = {
otp: "20420",
}
};
export const google_profile = {
email: "[email protected]",
password: "[email protected]",
Expand Down

0 comments on commit 45dddc2

Please sign in to comment.