Skip to content

Refactored tests and aligned them with the ComplianceCheck model #137

Refactored tests and aligned them with the ComplianceCheck model

Refactored tests and aligned them with the ComplianceCheck model #137

Workflow file for this run

name: CI/CD Pipeline
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
services:
mongodb:
image: mongo:6.0 # Pin MongoDB version for consistency
ports:
- 27017:27017
env:
MONGODB_URI: mongodb://localhost:27017/open-cap-stack
PORT: 5000
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '16' # Update Node.js version to a stable, supported version
- name: Install dependencies
run: npm ci # Ensures clean installation from package-lock.json
- name: Install dev dependencies
run: npm install --save-dev jest chai supertest sinon dotenv chai-http
- name: Check installed packages
run: npm list mongoose # Debugging step to confirm mongoose version
- name: Set up MongoDB logs
run: mkdir -p logs && touch logs/mongo.log # Prepare logs directory for MongoDB
- name: Wait for MongoDB to start
run: |
sleep 10
echo "Waiting for MongoDB to start..." # Ensures MongoDB is ready before testing
- name: Run tests
env:
MONGO_URI: ${{ env.MONGODB_URI }} # Explicitly pass env variables to the test step
run: npm test
- name: Print MongoDB logs
run: docker logs $(docker ps -q --filter "ancestor=mongo:6.0") || echo "No MongoDB logs available"
- name: Start application
env:
MONGO_URI: ${{ env.MONGODB_URI }} # Ensure the app uses the correct DB URI
PORT: ${{ env.PORT }}
run: npm start