Skip to content

Merge pull request #26 from Joseph19820124/claude/issue-25-20250910-1204 #4

Merge pull request #26 from Joseph19820124/claude/issue-25-20250910-1204

Merge pull request #26 from Joseph19820124/claude/issue-25-20250910-1204 #4

Workflow file for this run

name: Comprehensive Test Suite
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
jobs:
test-posts-service:
name: Posts Service Tests
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: posts-service/package-lock.json
- name: Install dependencies
working-directory: ./posts-service
run: npm ci
- name: Run unit tests
working-directory: ./posts-service
run: npm run test:unit
- name: Run integration tests
working-directory: ./posts-service
run: npm run test:integration
- name: Generate coverage report
working-directory: ./posts-service
run: npm run test:coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./posts-service/coverage/lcov.info
flags: posts-service
name: posts-service-coverage
fail_ci_if_error: false
test-comments-service:
name: Comments Service Tests
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: comments-service/package-lock.json
- name: Install dependencies
working-directory: ./comments-service
run: npm ci
- name: Run unit tests
working-directory: ./comments-service
run: npm run test:unit
- name: Run integration tests
working-directory: ./comments-service
run: npm run test:integration
- name: Generate coverage report
working-directory: ./comments-service
run: npm run test:coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./comments-service/coverage/lcov.info
flags: comments-service
name: comments-service-coverage
fail_ci_if_error: false
security-tests:
name: Security Tests
runs-on: ubuntu-latest
needs: [test-posts-service, test-comments-service]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18.x'
cache: 'npm'
- name: Install dependencies for all services
run: |
cd posts-service && npm ci
cd ../comments-service && npm ci
- name: Run security tests
run: npx jest tests/security/ --verbose
- name: Run OWASP ZAP Baseline Scan
uses: zaproxy/action-baseline@v0.10.0
with:
target: 'http://localhost:4000'
rules_file_name: '.zap/rules.tsv'
cmd_options: '-a'
performance-tests:
name: Performance Tests
runs-on: ubuntu-latest
needs: [test-posts-service, test-comments-service]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18.x'
cache: 'npm'
- name: Install dependencies for all services
run: |
cd posts-service && npm ci
cd ../comments-service && npm ci
- name: Run performance tests
run: npx jest tests/performance/ --verbose --testTimeout=60000
- name: Upload performance results
uses: actions/upload-artifact@v3
with:
name: performance-results
path: performance-results.json
retention-days: 30
e2e-tests:
name: End-to-End Tests
runs-on: ubuntu-latest
needs: [test-posts-service, test-comments-service]
services:
mongodb:
image: mongo:6.0
ports:
- 27017:27017
options: >-
--health-cmd "mongosh --eval 'db.runCommand(\"ping\").ok'"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18.x'
cache: 'npm'
- name: Install dependencies for all services
run: |
cd posts-service && npm ci
cd ../comments-service && npm ci
- name: Start posts service
working-directory: ./posts-service
run: |
npm start &
sleep 10
env:
NODE_ENV: test
PORT: 4000
MONGODB_URI: mongodb://localhost:27017/posts_service_e2e
- name: Start comments service
working-directory: ./comments-service
run: |
npm start &
sleep 10
env:
NODE_ENV: test
PORT: 4001
MONGODB_URI: mongodb://localhost:27017/comments_service_e2e
- name: Wait for services to be ready
run: |
timeout 30 bash -c 'until curl -f http://localhost:4000/health; do sleep 2; done'
timeout 30 bash -c 'until curl -f http://localhost:4001/health; do sleep 2; done'
- name: Run end-to-end tests
run: npx jest tests/e2e/ --verbose --testTimeout=60000
env:
POSTS_SERVICE_URL: http://localhost:4000
COMMENTS_SERVICE_URL: http://localhost:4001
code-quality:
name: Code Quality Checks
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18.x'
cache: 'npm'
- name: Install dependencies
run: |
cd posts-service && npm ci
cd ../comments-service && npm ci
- name: Run ESLint (if configured)
run: |
if [ -f "posts-service/.eslintrc.json" ]; then
cd posts-service && npx eslint . --ext .js
fi
if [ -f "comments-service/.eslintrc.json" ]; then
cd comments-service && npx eslint . --ext .js
fi
continue-on-error: true
- name: Run Prettier check (if configured)
run: |
if [ -f "posts-service/.prettierrc" ]; then
cd posts-service && npx prettier --check .
fi
if [ -f "comments-service/.prettierrc" ]; then
cd comments-service && npx prettier --check .
fi
continue-on-error: true
- name: Check for security vulnerabilities
run: |
cd posts-service && npm audit --audit-level moderate
cd ../comments-service && npm audit --audit-level moderate
docker-tests:
name: Docker Container Tests
runs-on: ubuntu-latest
needs: [test-posts-service, test-comments-service]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build posts service Docker image
run: |
cd posts-service
docker build -t posts-service:test .
- name: Build comments service Docker image
run: |
cd comments-service
docker build -t comments-service:test .
- name: Test Docker containers
run: |
# Start MongoDB for testing
docker run -d --name mongodb -p 27017:27017 mongo:6.0
sleep 10
# Start posts service container
docker run -d --name posts-service \
-p 4000:4000 \
-e NODE_ENV=test \
-e MONGODB_URI=mongodb://host.docker.internal:27017/posts_service_docker_test \
--add-host host.docker.internal:host-gateway \
posts-service:test
# Start comments service container
docker run -d --name comments-service \
-p 4001:4001 \
-e NODE_ENV=test \
-e MONGODB_URI=mongodb://host.docker.internal:27017/comments_service_docker_test \
--add-host host.docker.internal:host-gateway \
comments-service:test
# Wait for services to be ready
sleep 15
# Test health endpoints
curl -f http://localhost:4000/health || exit 1
curl -f http://localhost:4001/health || exit 1
# Cleanup
docker stop posts-service comments-service mongodb
docker rm posts-service comments-service mongodb
generate-report:
name: Generate Test Report
runs-on: ubuntu-latest
needs: [test-posts-service, test-comments-service, security-tests, performance-tests, e2e-tests]
if: always()
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v3
- name: Generate comprehensive test report
run: |
echo "# Test Suite Results" > test-report.md
echo "## Build Information" >> test-report.md
echo "- **Branch**: ${{ github.ref_name }}" >> test-report.md
echo "- **Commit**: ${{ github.sha }}" >> test-report.md
echo "- **Run ID**: ${{ github.run_id }}" >> test-report.md
echo "- **Timestamp**: $(date -u)" >> test-report.md
echo "" >> test-report.md
echo "## Test Results Summary" >> test-report.md
echo "| Test Suite | Status |" >> test-report.md
echo "|------------|--------|" >> test-report.md
echo "| Posts Service Unit Tests | ${{ needs.test-posts-service.result }} |" >> test-report.md
echo "| Comments Service Unit Tests | ${{ needs.test-comments-service.result }} |" >> test-report.md
echo "| Security Tests | ${{ needs.security-tests.result }} |" >> test-report.md
echo "| Performance Tests | ${{ needs.performance-tests.result }} |" >> test-report.md
echo "| End-to-End Tests | ${{ needs.e2e-tests.result }} |" >> test-report.md
- name: Upload test report
uses: actions/upload-artifact@v3
with:
name: test-report
path: test-report.md
retention-days: 30
notification:
name: Notify on Failure
runs-on: ubuntu-latest
needs: [test-posts-service, test-comments-service, security-tests, performance-tests, e2e-tests]
if: failure()
steps:
- name: Notify on test failure
run: |
echo "❌ Test suite failed for commit ${{ github.sha }}"
echo "Check the workflow run for details: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"