Skip to content

feat: Add comprehensive test suite for curriculum and progress servic… #2

feat: Add comprehensive test suite for curriculum and progress servic…

feat: Add comprehensive test suite for curriculum and progress servic… #2

Workflow file for this run

name: Backend Tests
on:
push:
branches: [ main, develop ]
paths:
- 'backend/**'
- '.github/workflows/backend-tests.yml'
pull_request:
branches: [ main, develop ]
paths:
- 'backend/**'
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x]
services:
postgres:
image: postgres:15
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: test_db
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
redis:
image: redis:7
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: backend/package-lock.json
- name: Install dependencies
working-directory: ./backend
run: npm ci
- name: Run Prisma generate
working-directory: ./backend
env:
DATABASE_URL: postgresql://test:test@localhost:5432/test_db
run: npx prisma generate
- name: Run database migrations
working-directory: ./backend
env:
DATABASE_URL: postgresql://test:test@localhost:5432/test_db
run: npx prisma migrate deploy || true
- name: Run tests with coverage
working-directory: ./backend
env:
NODE_ENV: test
DATABASE_URL: postgresql://test:test@localhost:5432/test_db
REDIS_URL: redis://localhost:6379
JWT_SECRET: test-jwt-secret
run: npm run test:coverage
- name: Check coverage threshold
working-directory: ./backend
run: |
coverage=$(cat coverage/coverage-summary.json | jq '.total.lines.pct')
echo "Coverage: $coverage%"
if (( $(echo "$coverage < 90" | bc -l) )); then
echo "❌ Coverage $coverage% is below 90% threshold"
exit 1
fi
echo "✅ Coverage $coverage% meets the 90% threshold"
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: ./backend/coverage/lcov.info
flags: backend
name: backend-coverage
fail_ci_if_error: false
- name: Comment PR with coverage
if: github.event_name == 'pull_request'
uses: romeovs/lcov-reporter-action@v0.3.1
with:
lcov-file: ./backend/coverage/lcov.info
github-token: ${{ secrets.GITHUB_TOKEN }}
delete-old-comments: true