added api tests #12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 🧪 Test | |
| on: | |
| pull_request: | |
| push: | |
| branches: [main] | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| services: | |
| db_test: | |
| image: postgres:15 | |
| env: | |
| POSTGRES_USER: postgres | |
| POSTGRES_PASSWORD: postgres | |
| POSTGRES_DB: fitnesstracker_test | |
| ports: | |
| - 5433:5432 | |
| options: >- | |
| --health-cmd="pg_isready -U postgres" | |
| --health-interval=10s | |
| --health-timeout=5s | |
| --health-retries=5 | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Use Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: 18 | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Generate Prisma client & push schema | |
| env: | |
| NODE_ENV: test | |
| DATABASE_URL: postgres://postgres:postgres@localhost:5433/fitnesstracker_test?schema=public | |
| run: | | |
| npx prisma generate | |
| npx prisma db push | |
| - name: Run tests | |
| env: | |
| NODE_ENV: test | |
| DATABASE_URL: postgres://postgres:postgres@localhost:5433/fitnesstracker_test?schema=public | |
| run: npm test | |
| - name: Upload test results | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: jest-test-results | |
| path: test-results/jest-junit.xml | |
| - name: Code Coverage Report | |
| uses: irongut/[email protected] | |
| with: | |
| filename: coverage/cobertura-coverage.xml | |
| badge: true | |
| fail_below_min: true | |
| format: markdown | |
| hide_branch_rate: false | |
| hide_complexity: true | |
| indicators: true | |
| output: both | |
| thresholds: '60 80' | |
| - name: Add Coverage PR Comment | |
| uses: marocchino/sticky-pull-request-comment@v2 | |
| if: github.event_name == 'pull_request' | |
| with: | |
| recreate: true | |
| path: code-coverage-results.md |