Skip to content

Commit

Permalink
chore : Set up Tests locally & implement Continuous Integration
Browse files Browse the repository at this point in the history
  • Loading branch information
soleil00 committed Apr 17, 2024
1 parent c915dfa commit ae0c531
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 3 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Eagle e-commerce CI/CD

on:
push:
branches:
- main
- dev

pull_request:
branches:
- main
- dev

workflow_dispatch:

jobs:
build:
name: Building code
runs-on: ubuntu-latest

steps:
- name: Checkout the code
uses: actions/checkout@v3

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: "20"

- name: Install dependencies
run: npm install

- name: Running test
env:
DB_CONNECTION: ${{ secrets.DB_CONNECTION }}
TEST_DB: ${{ secrets.TEST_DB }}
run: npm run test

- name: Build application
run: npm run build

- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: soleil00/eagles-ec-be

- name: Trigger Render Deployment
env:
RENDER_DEPLOYMENT_HOOK_URL: ${{ secrets.RENDER_DEPLOYMENT_HOOK_URL }}
run: |
curl -X POST $RENDER_DEPLOYMENT_HOOK_URL
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
# eagles-ec-be

<div style="display: flex; justify-content: center;" align="center">
<img src="https://codecov.io/gh/soleil00/eagles-ec-be/branch/dev/graph/badge.svg?token=9c1e8e93-1062-4e49-a58d-b2777a75fb70" alt="Codecov" >
<img alt="GitHub Actions Workflow Status" src="https://img.shields.io/github/actions/workflow/status/soleil00/eagles-ec-be/test.yml" >
<a href="https://codeclimate.com/github/atlp-rwanda/eagles-ec-be/maintainability"><img src="https://api.codeclimate.com/v1/badges/dfe8454356fb9da65407/maintainability" /></a>

</div>

### Technology used

![Node.js](https://img.shields.io/badge/-Node.js-000000?style=flat&logo=node.js)
[![Passport.js](https://img.shields.io/badge/auth%20library-Passport.js-green)](http://www.passportjs.org/)
[![PostgreSQL](https://img.shields.io/badge/database-PostgreSQL-blue)](https://www.postgresql.org/)
[![Sequelize](https://img.shields.io/badge/ORM-Sequelize-orange)](https://sequelize.org/)
[![Jest](https://img.shields.io/badge/testing-Jest-red)](https://jestjs.io/)
[![ESLint](https://img.shields.io/badge/code%20style-ESLint-blueviolet)](https://eslint.org/)
1 change: 0 additions & 1 deletion __test__/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ describe("Testing user Routes", () => {
const response = await request(app).get("/api/v1/users");
expect(spy).toHaveBeenCalled();
expect(spy2).toHaveBeenCalled();
expect(response.statusCode).toBe(200);
}, 20000);
});
11 changes: 11 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
testMatch: ["**/**/*.test.ts"],
verbose: true,
forceExit: true,
clearMocks: true,
resetMocks: true,
restoreMocks: true,
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"seed": "npx sequelize-cli db:seed:all",
"lint": "npx eslint .",
"lint:fix": "npx eslint --fix .",
"test": " npm run lint && jest --detectOpenHandles --coverage"
"test": "jest --detectOpenHandles --coverage"
},
"author": "atlp",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/config/testDbConfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Sequelize } from "sequelize";
import { env } from "../utils/env";

export const testSequelize = new Sequelize(env.db_url);
export const testSequelize = new Sequelize(env.test_db_url);
export const testDbConnection = async () => {
try {
await testSequelize.authenticate();
Expand Down
1 change: 1 addition & 0 deletions src/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ dotenv.config();
export const env = {
port: process.env.PORT || 3000,
db_url: process.env.DB_CONNECTION as string,
test_db_url: process.env.TEST_DB as string,
};

0 comments on commit ae0c531

Please sign in to comment.