Fix environment config: preview deployments should use production data #45
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: Automated Route Testing | |
| on: | |
| push: | |
| branches: [ main, dev ] | |
| pull_request: | |
| branches: [ main, dev ] | |
| schedule: | |
| # Run tests daily at 2 AM UTC | |
| - cron: '0 2 * * *' | |
| jobs: | |
| quick-route-tests: | |
| name: Quick Route Validation | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run quick route tests | |
| run: npm run test:routes:quick | |
| - name: Upload quick test results | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: quick-test-results | |
| path: test-reports/ | |
| comprehensive-route-tests: | |
| name: Comprehensive Route Testing | |
| runs-on: ubuntu-latest | |
| needs: quick-route-tests | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run comprehensive route tests | |
| run: npm run test:routes:full | |
| - name: Run API endpoint tests | |
| run: npm run test:api | |
| - name: Run page route tests | |
| run: npm run test:pages | |
| - name: Upload comprehensive test results | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: comprehensive-test-results | |
| path: test-reports/ | |
| integration-tests: | |
| name: Integration Testing | |
| runs-on: ubuntu-latest | |
| needs: quick-route-tests | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run user flow tests | |
| run: npm run test:flows | |
| - name: Run integration tests | |
| run: npm run test:integration | |
| - name: Upload integration test results | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: integration-test-results | |
| path: test-reports/ | |
| security-tests: | |
| name: Security Testing | |
| runs-on: ubuntu-latest | |
| needs: quick-route-tests | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run API security tests | |
| run: npm run test:api:security | |
| - name: Run route security validation | |
| run: npm run test:routes -- --testNamePattern="Security" | |
| - name: Upload security test results | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: security-test-results | |
| path: test-reports/ | |
| live-server-tests: | |
| name: Live Server Testing | |
| runs-on: ubuntu-latest | |
| needs: comprehensive-route-tests | |
| if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build application | |
| run: npm run build | |
| - name: Start test server | |
| run: | | |
| npm start & | |
| sleep 30 | |
| - name: Wait for server to be ready | |
| run: | | |
| timeout 60 bash -c 'until curl -f http://localhost:3000/api/random-pages; do sleep 2; done' | |
| - name: Run live API tests | |
| run: npm run test:api:live | |
| - name: Run live integration tests | |
| run: npm run test:flows:live | |
| - name: Upload live test results | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: live-test-results | |
| path: test-reports/ | |
| performance-tests: | |
| name: Performance Testing | |
| runs-on: ubuntu-latest | |
| needs: comprehensive-route-tests | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run performance tests | |
| run: npm run test:api:performance | |
| - name: Run flow performance tests | |
| run: npm run test:flows:performance | |
| - name: Upload performance test results | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: performance-test-results | |
| path: test-reports/ | |
| test-report: | |
| name: Generate Test Report | |
| runs-on: ubuntu-latest | |
| needs: [comprehensive-route-tests, integration-tests, security-tests] | |
| if: always() | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download all test results | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: test-results/ | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Generate consolidated report | |
| run: node app/scripts/generate-test-report.js | |
| - name: Upload consolidated report | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: consolidated-test-report | |
| path: test-reports/consolidated-report.html | |
| - name: Comment PR with test results | |
| if: github.event_name == 'pull_request' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const path = 'test-reports/test-summary.json'; | |
| if (fs.existsSync(path)) { | |
| const summary = JSON.parse(fs.readFileSync(path, 'utf8')); | |
| const comment = `## 🧪 Automated Test Results | |
| **Route Tests:** ${summary.routes.passed}/${summary.routes.total} passed (${summary.routes.successRate}%) | |
| **API Tests:** ${summary.api.passed}/${summary.api.total} passed (${summary.api.successRate}%) | |
| **Page Tests:** ${summary.pages.passed}/${summary.pages.total} passed (${summary.pages.successRate}%) | |
| **Integration Tests:** ${summary.integration.passed}/${summary.integration.total} passed (${summary.integration.successRate}%) | |
| ${summary.overall.failed > 0 ? '❌ Some tests failed. Please review the detailed results.' : '✅ All tests passed!'} | |
| [View detailed report](${summary.reportUrl})`; | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: comment | |
| }); | |
| } | |
| notify-on-failure: | |
| name: Notify on Test Failure | |
| runs-on: ubuntu-latest | |
| needs: [comprehensive-route-tests, integration-tests, security-tests] | |
| if: failure() && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev') | |
| steps: | |
| - name: Send notification | |
| run: | | |
| echo "🚨 Automated tests failed on ${{ github.ref }}" | |
| echo "Please check the test results and fix any issues." | |
| # Add your notification logic here (Slack, email, etc.) | |
| env: | |
| NODE_ENV: test | |
| CI: true |