Skip to content

Commit

Permalink
add some extra functions to github action workflow
Browse files Browse the repository at this point in the history
Signed-off-by: Amit Amrutiya <[email protected]>
  • Loading branch information
amitamrutiya committed Feb 13, 2024
1 parent 68f55c9 commit c1731ed
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 50 deletions.
31 changes: 16 additions & 15 deletions .github/workflows/workflow_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,33 @@ name: Backend CI

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]

jobs:
build:

runs-on: ubuntu-latest
defaults:
run:
working-directory: ./backend

steps:
- uses: actions/checkout@v2
with:
path: 'backend'
ref: main
- uses: actions/checkout@v2
with:
path: "backend"
ref: main

- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: '20.x'
- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: "20.x"

- name: Install Dependencies
run: npm install
- name: Install Dependencies
run: npm install

- name: Run ESLint
run: npm run format
- name: Run ESLint
run: npm run format

- name: Run Tests
run: npm run test
8 changes: 7 additions & 1 deletion .github/workflows/workflow_frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,10 @@ jobs:
run: npm install vite

- name: Run ESLint
run: npm run format
run: npm run format

- name: Run Tests
run: npm run test

- name: Build
run: npm run build
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"start": "node -r dotenv/config --experimental-json-modules index.js",
"dev": "nodemon -r dotenv/config --experimental-json-modules index.js",
"test": "jest",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
"build": "npm i",
"format": "cd .. && npm run format"
},
Expand Down
31 changes: 0 additions & 31 deletions backend/test/models/category.model.test.js

This file was deleted.

15 changes: 15 additions & 0 deletions backend/test/utils/secToDuration.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import convertSecondsToDuration from "../../utils/secToDuration";

Check failure on line 1 in backend/test/utils/secToDuration.test.js

View workflow job for this annotation

GitHub Actions / build

Extra semicolon

Check failure on line 1 in backend/test/utils/secToDuration.test.js

View workflow job for this annotation

GitHub Actions / build

Extra semicolon

describe("convertSecondsToDuration", () => {

Check failure on line 3 in backend/test/utils/secToDuration.test.js

View workflow job for this annotation

GitHub Actions / build

'describe' is not defined

Check failure on line 3 in backend/test/utils/secToDuration.test.js

View workflow job for this annotation

GitHub Actions / build

'describe' is not defined
it("should correctly convert seconds to hours and minutes", () => {

Check failure on line 4 in backend/test/utils/secToDuration.test.js

View workflow job for this annotation

GitHub Actions / build

'it' is not defined

Check failure on line 4 in backend/test/utils/secToDuration.test.js

View workflow job for this annotation

GitHub Actions / build

'it' is not defined
expect(convertSecondsToDuration(3661)).toBe("1h 1m");

Check failure on line 5 in backend/test/utils/secToDuration.test.js

View workflow job for this annotation

GitHub Actions / build

'expect' is not defined

Check failure on line 5 in backend/test/utils/secToDuration.test.js

View workflow job for this annotation

GitHub Actions / build

Extra semicolon

Check failure on line 5 in backend/test/utils/secToDuration.test.js

View workflow job for this annotation

GitHub Actions / build

'expect' is not defined

Check failure on line 5 in backend/test/utils/secToDuration.test.js

View workflow job for this annotation

GitHub Actions / build

Extra semicolon
});

Check failure on line 6 in backend/test/utils/secToDuration.test.js

View workflow job for this annotation

GitHub Actions / build

Extra semicolon

Check failure on line 6 in backend/test/utils/secToDuration.test.js

View workflow job for this annotation

GitHub Actions / build

Extra semicolon

it("should correctly convert seconds to minutes and seconds", () => {

Check failure on line 8 in backend/test/utils/secToDuration.test.js

View workflow job for this annotation

GitHub Actions / build

'it' is not defined

Check failure on line 8 in backend/test/utils/secToDuration.test.js

View workflow job for this annotation

GitHub Actions / build

'it' is not defined
expect(convertSecondsToDuration(61)).toBe("1m 1s");

Check failure on line 9 in backend/test/utils/secToDuration.test.js

View workflow job for this annotation

GitHub Actions / build

'expect' is not defined

Check failure on line 9 in backend/test/utils/secToDuration.test.js

View workflow job for this annotation

GitHub Actions / build

Extra semicolon

Check failure on line 9 in backend/test/utils/secToDuration.test.js

View workflow job for this annotation

GitHub Actions / build

'expect' is not defined

Check failure on line 9 in backend/test/utils/secToDuration.test.js

View workflow job for this annotation

GitHub Actions / build

Extra semicolon
});

Check failure on line 10 in backend/test/utils/secToDuration.test.js

View workflow job for this annotation

GitHub Actions / build

Extra semicolon

Check failure on line 10 in backend/test/utils/secToDuration.test.js

View workflow job for this annotation

GitHub Actions / build

Extra semicolon

it("should correctly convert seconds to seconds", () => {
expect(convertSecondsToDuration(1)).toBe("1s");
});
});
4 changes: 2 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build": "vite build",
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
"test": "vitest",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
"format": "cd .. && npm run format"
},
"dependencies": {
Expand Down Expand Up @@ -48,4 +48,4 @@
"vite": "^4.4.5",
"vitest": "^0.34.6"
}
}
}
23 changes: 23 additions & 0 deletions frontend/src/test/utils/avgRating.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import GetAvgRating from "../../utils/avgRating";

describe("GetAvgRating", () => {
it("should return 0 when the array is empty", () => {
expect(GetAvgRating([])).toBe(0);
});

it("should correctly calculate the average rating", () => {
const ratings = [
{ rating: 5 },
{ rating: 4 },
{ rating: 3 },
{ rating: 2 },
{ rating: 1 },
];
expect(GetAvgRating(ratings)).toBe(3);
});

it("should correctly round the average rating to one decimal place", () => {
const ratings = [{ rating: 5 }, { rating: 4 }, { rating: 4 }];
expect(GetAvgRating(ratings)).toBe(4.3);
});
});

0 comments on commit c1731ed

Please sign in to comment.