diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..c43dc1b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,45 @@ +name: Continuous Integration + +on: + pull_request: + branches: + - main + - dev + +jobs: + testing: + runs-on: ubuntu-latest + services: + mysql: + image: mysql:5.7 + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: techstart-fashion + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping -h localhost -uroot -proot" + --health-interval=10s + --health-timeout=5s + --health-retries=5 + + env: + DATABASE_URL: mysql://root:root@localhost:3306/techstart-fashion + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install dependencies + run: cd backend && npm install + + - name: Wait for database + run: | + until nc -z localhost 3306; do + echo "Waiting for MySQL to be ready..." + sleep 2 + done + echo "MySQL is ready." + + - name: Test + run: cd backend && npm run test diff --git a/README.md b/README.md index cfcc9e6..7057397 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # ♻️ Fashion +[![Continuous Integration](https://github.com/techstartucalgary/fashion/actions/workflows/ci.yml/badge.svg)](https://github.com/techstartucalgary/fashion/actions/workflows/ci.yml) + ## 📖 Table of Contents - [📝 Contributors](#-contributors) diff --git a/backend/.github/workflows/ci.yml b/backend/.github/workflows/ci.yml deleted file mode 100644 index 433c1cb..0000000 --- a/backend/.github/workflows/ci.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Continuous Integration - -on: - pull_request: - branches: - - main - - dev - -jobs: - - testing: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Install dependencies - run: npm install - - - name: Test - run: npm run test diff --git a/backend/package.json b/backend/package.json index 3643095..7aa3dfc 100644 --- a/backend/package.json +++ b/backend/package.json @@ -10,7 +10,7 @@ "start": "NODE_ENV=PROD node dist/src/index.js", "predev": "npx prisma migrate dev --name init && npx prisma generate", "dev": "NODE_ENV=DEV nodemon -e ts --exec \"npm run build && node dist/src/index.js\"", - "pretest": "npx prisma migrate deploy && npx prisma generate", + "pretest": "npx prisma migrate dev --name init && npx prisma generate", "test": "NODE_ENV=TEST npm run build && mocha \"dist/test/**/*.test.js\"" }, "keywords": [], diff --git a/backend/src/index.ts b/backend/src/index.ts index 6e28f84..5d26cca 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -4,12 +4,9 @@ import algorithmRouter from "./routers/algorithm.router.js"; import authenticationRouter from "./routers/authentication.router.js"; import errorHandler from "./middlewares/error.middleware.js"; import { PORT } from "./config/config.js"; -import { PrismaClient } from "@prisma/client"; export const app: Express = express(); -export const prisma = new PrismaClient(); - app.use(cors()); app.use(express.json()); diff --git a/backend/src/routers/authentication.router.ts b/backend/src/routers/authentication.router.ts index 3d7f66d..7f074fc 100644 --- a/backend/src/routers/authentication.router.ts +++ b/backend/src/routers/authentication.router.ts @@ -1,5 +1,5 @@ import { Router } from "express"; -import { prisma } from "../index.js"; +import { PrismaClient } from "@prisma/client"; import UserRepository from "../repositories/user.repository.js"; import AuthenticationService from "../services/authentication.service.js"; import AuthenticationController from "../controllers/authentication.controller.js"; @@ -11,6 +11,8 @@ import { const authenticationRouter = Router(); +const prisma = new PrismaClient(); + const userRepository: UserRepositoryInterface = new UserRepository(prisma); const authenticationService: AuthenticationServiceInterface =