Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
026b6e5
build(deps): bump passport from 0.3.2 to 0.6.0
dependabot[bot] Feb 17, 2024
5196596
build(deps): bump validator and express-validator
dependabot[bot] Feb 17, 2024
792e549
chore(automated-tests): Add CI workflow for HRMS and specify Node.js …
muneeb706 May 13, 2025
d5526ae
chore(automated-tests): Add CI workflow for HRMS and specify Node.js …
muneeb706 May 13, 2025
239cf83
chore(ci): Add MongoDB service to CI workflow for testing
muneeb706 May 13, 2025
3ca1ae1
chore(tests): Enhance test setup with error handling and logging
muneeb706 May 13, 2025
413506f
chore(ci): Add test database URL to HRMS CI workflow
muneeb706 May 13, 2025
24bbeb1
chore(tests): Refactor test setup to improve database connection and …
muneeb706 May 13, 2025
41e3e60
chore(tests): Update user seeder execution to display command output …
muneeb706 May 13, 2025
c47718d
chore(seeding): Refactor user seeder to improve error handling and lo…
muneeb706 May 13, 2025
a9e1b62
chore(tests): Update test setup logging for clarity and consistency
muneeb706 May 13, 2025
65828a7
chore(tests): Update Jest configuration to use setupFilesAfterEnv for…
muneeb706 May 13, 2025
9c03fdb
chore(tests): Update test setup to use global agents and improve logging
muneeb706 May 13, 2025
b9444f3
chore(tests): Remove unused csrfToken and simplify agent login refere…
muneeb706 May 13, 2025
47cea83
chore(tests): Add console log for admin agent in test setup for debug…
muneeb706 May 13, 2025
97ac24f
chore(tests): Refactor user seeder and test setup for improved clarit…
muneeb706 May 13, 2025
4cd09cb
chore(tests): Enhance CI workflow with MongoDB connection debugging a…
muneeb706 May 13, 2025
17a6e26
chore(tests): Remove MongoDB connection debugging from CI workflow
muneeb706 May 13, 2025
814b647
chore(tests): Refactor project manager agent setup and cleanup in tes…
muneeb706 May 13, 2025
8c30155
chore(tests): Update project manager agent initialization in tests fo…
muneeb706 May 13, 2025
3875254
chore(tests): Refactor project manager route tests to include databas…
muneeb706 May 13, 2025
d41267e
chore(tests): Implement employee agent setup and teardown in employee…
muneeb706 May 13, 2025
e65c26c
chore(tests): Enhance admin and employee route tests with agent setup…
muneeb706 May 13, 2025
0052e6b
Merge pull request #6 from muneeb706/dependabot/npm_and_yarn/passport…
muneeb706 May 13, 2025
52979c8
Merge pull request #9 from muneeb706/dependabot/npm_and_yarn/validato…
muneeb706 May 13, 2025
feaed50
chore(dependencies): downgrade express-validator to version 4.0.0
muneeb706 May 13, 2025
9d2651d
Merge branch 'master' into chore/dependency-updates
muneeb706 May 13, 2025
498a00c
chore(dependencies): downgrade express and passport to earlier versions
muneeb706 May 13, 2025
ed76ff6
docs: update README to indicate repository is no longer maintained
muneeb706 May 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/hrms.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: HRMS CI

on:
push:
branches:
- master
pull_request:
branches:
- master

env:
DB_URL_TEST: mongodb://localhost:27017/test-db

jobs:
test:
runs-on: ubuntu-latest

services:
mongo:
image: mongo:5.0
ports:
- 27017:27017
options: >-
--health-cmd "mongo --eval 'db.runCommand({ ping: 1 })'"
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install dependencies
run: npm install

- name: Run tests
run: |
echo "Running tests..."
npm test
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,8 @@ Accounts Manager is also an employee with the ability to generate pay slip, set
1. Browser will redirect to the home page of the application.

### Run Tests
1. To run tests, in the terminal, at the root folder of application, type command **npm test**.
1. To run tests, in the terminal, at the root folder of application, type command **npm test**.

<br/>

**⚠️ Note: This repository is no longer maintained.**
2 changes: 0 additions & 2 deletions db.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ require("dotenv").config();

mongoose.Promise = global.Promise;

mongoose.Promise = global.Promise;

const connect = (opts = {}) => {
let url;
switch (process.env.NODE_ENV) {
Expand Down
27 changes: 15 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"csurf": "^1.9.0",
"dotenv": "^16.4.3",
"ejs": "~3.1.7",
"express": "^4.19.2",
"express": "^4.17.1",
"express-session": "^1.17.1",
"express-validator": "^4.0.0",
"moment": "^2.27.0",
Expand All @@ -40,8 +40,12 @@
"!<rootDir>/public/**",
"!<rootDir>/coverage/**",
"!<rootDir>/test/**",
"!<rootDir>/seed/**",
"!<rootDir>/node_modules/**"
],
"coverageProvider": "v8"
},
"engines": {
"node": ">=18.0.0"
}
}
2 changes: 1 addition & 1 deletion seed/user-seeder.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ let users = [
function exit() {
mongoose.disconnect();
console.log("Users Added...")
}
}
35 changes: 28 additions & 7 deletions test/routes/admin.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
const { expect } = require("@jest/globals");
const db = require("../../db");
const request = require("supertest");
const cheerio = require("cheerio");
const User = require("../../models/user");

describe("Admin Routes", () => {
let admin_agent = null;

beforeAll(async () => {
await db.connect();
const app = require("../../app");
admin_agent = request.agent(app);
const getRes = await admin_agent.get("/");
const $ = cheerio.load(getRes.text);
const csrfToken = $('input[name="_csrf"]').val();

await admin_agent.post("/login").send({
_csrf: csrfToken,
email: "admin@admin.com",
password: "admin123",
});
});

afterAll(async () => {
await admin_agent.get("/logout");
await db.close();
});

test("GET / should render admin home page", async () => {
const res = await admin_agent.get("/admin/");

Expand Down Expand Up @@ -35,13 +58,11 @@ describe("Admin Routes", () => {
test("GET /admin/employee-profile/:id should return employee profile", async () => {
let employeeId;
let employeeName;
await db.connect().then(async () => {
const employee = await User.findOne({ type: "accounts_manager" });
employeeId = employee._id;
employeeName = employee.name;
db.close();
});


const employee = await User.findOne({ type: "accounts_manager" });
employeeId = employee._id;
employeeName = employee.name;

const res = await admin_agent.get(`/admin/employee-profile/${employeeId}`);
expect(res.statusCode).toBe(200);

Expand Down
24 changes: 24 additions & 0 deletions test/routes/employee.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
const { expect } = require("@jest/globals");
const cheerio = require("cheerio");
const db = require("../../db");
const request = require("supertest");

describe("Employee Routes", () => {
let employee_agent = null;

beforeAll(async () => {
await db.connect();
const app = require("../../app");
employee_agent = request.agent(app);
const getRes = await employee_agent.get("/");
const $ = cheerio.load(getRes.text);
const csrfToken = $('input[name="_csrf"]').val();

await employee_agent.post("/login").send({
_csrf: csrfToken,
email: "employee1@employee.com",
password: "123456",
});
});

afterAll(async () => {
await employee_agent.get("/logout");
await db.close();
});

test("GET / should render employee home page", async () => {
const res = await employee_agent.get("/employee/");

Expand Down
32 changes: 29 additions & 3 deletions test/routes/manager.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
const { expect } = require("@jest/globals");
const { expect, beforeAll, afterAll } = require("@jest/globals");
const cheerio = require("cheerio");
const db = require("../../db");
const request = require("supertest");


describe("Project Manager Routes", () => {
let pm_agent = null;

beforeAll(async () => {
await db.connect();
const app = require("../../app");
pm_agent = request.agent(app);
const getRes = await pm_agent.get("/");
const $ = cheerio.load(getRes.text);
const csrfToken = $('input[name="_csrf"]').val();

await pm_agent.post("/login").send({
_csrf: csrfToken,
email: "pm@pm.com",
password: "pm1234",
});

});

afterAll(async () => {
await pm_agent.get("/logout");
await db.close();
});

describe("Employee Routes", () => {
test("GET / should render project manager home page", async () => {
const res = await pm_agent.get("/manager/");

Expand All @@ -16,4 +42,4 @@ describe("Employee Routes", () => {
expect(icon).toHaveLength(1);
expect(text).toBe("Project manager");
});
});
});
41 changes: 7 additions & 34 deletions test/setupTests.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,11 @@
const db = require("../db");
const request = require("supertest");
const cheerio = require("cheerio");
const execSync = require("child_process").execSync;

global.admin_agent = null;
global.employee_agent = null;
global.pm_agent = null;
global.csrfToken = null;

module.exports = async () => {
await db.connect().then(() => {
try {
execSync("NODE_ENV=test node seed/user-seeder.js");
const app = require("../app");
admin_agent = request.agent(app);
employee_agent = request.agent(app);
pm_agent = request.agent(app);
csrfToken = null;
});

await loginAs(admin_agent, "admin@admin.com", "admin123");
await loginAs(employee_agent, "employee1@employee.com", "123456");
await loginAs(pm_agent, "pm@pm.com", "pm1234");
};

async function loginAs(agent, email, password) {
const getRes = await agent.get("/");
const $ = cheerio.load(getRes.text);
const csrfToken = $('input[name="_csrf"]').val();

await agent.post("/login").send({
_csrf: csrfToken,
email: email,
password: password,
});

return agent;
}
console.log("Database seeded")
} catch (error) {
console.error("Setup failed:", error);
throw error;
}
};
19 changes: 8 additions & 11 deletions test/teardownTests.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
const app = require("../app");
const db = require("../db");
//const app = require("../app");
//const db = require("../db");

module.exports = async () => {
await admin_agent.get("/logout");
await employee_agent.get("/logout");
await pm_agent.get("/logout");

await db.close();

//await db.close();
// If your app doesn't close the server automatically, you can do it manually
if (app && app.close) {
app.close();
}
};
// if (app && app.close) {
// //app.close();
// }
};