From 96087853961e4a46cc6ba05a873879f069e2f459 Mon Sep 17 00:00:00 2001 From: Aditya Rathore <153427299+AdityaDRathore@users.noreply.github.com> Date: Sat, 17 May 2025 20:05:06 +0000 Subject: [PATCH 1/2] fix: load environment variables in database connection test --- backend/src/tests/db-connection.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/src/tests/db-connection.test.ts b/backend/src/tests/db-connection.test.ts index 3f5bc7c..c494e4d 100644 --- a/backend/src/tests/db-connection.test.ts +++ b/backend/src/tests/db-connection.test.ts @@ -1,4 +1,8 @@ import { PrismaClient } from '@prisma/client'; +import * as dotenv from 'dotenv'; + +// Load environment variables +dotenv.config(); describe('Database Connection', () => { let prisma: PrismaClient; @@ -13,7 +17,7 @@ describe('Database Connection', () => { it('should connect to the database successfully', async () => { if (!process.env.DATABASE_URL) { - // Remove console.log and use return to skip test + console.warn('DATABASE_URL not found, skipping test'); return; } From 5762b61c5c887bc0670571faa2a5b2a310931bd2 Mon Sep 17 00:00:00 2001 From: Aditya Rathore <153427299+AdityaDRathore@users.noreply.github.com> Date: Sat, 17 May 2025 20:34:00 +0000 Subject: [PATCH 2/2] feat: add PostgreSQL service container and .env file creation in CI workflow --- .github/workflows/backend-ci.yml | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/.github/workflows/backend-ci.yml b/.github/workflows/backend-ci.yml index 4a93cee..d5438f9 100644 --- a/.github/workflows/backend-ci.yml +++ b/.github/workflows/backend-ci.yml @@ -16,6 +16,23 @@ jobs: build-and-test: runs-on: ubuntu-latest + # Add PostgreSQL service container + services: + postgres: + image: postgres:15-alpine + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: password + POSTGRES_DB: time_booking + ports: + - 5432:5432 + # Health check to ensure PostgreSQL is ready + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + defaults: run: working-directory: ./backend @@ -32,8 +49,11 @@ jobs: - name: Install dependencies run: npm install # Using install instead of ci - # Continue with other steps as before - + # Create .env file with DATABASE_URL + - name: Create .env file + run: | + echo "DATABASE_URL=postgresql://postgres:password@localhost:5432/time_booking?schema=public" > .env + - name: Fix linting issues run: npm run lint:fix