Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
NODE_ENV=test
DATABASE_URL=postgresql://test:test@localhost:5432/nepa_test
DB_USER=test
DB_PASSWORD=test
DB_NAME=nepa_test
DB_HOST=localhost
DB_PORT=5432
REDIS_URL=redis://localhost:6379

# Database Per Service Configuration (test)

# User Service Database
USER_SERVICE_DATABASE_URL="postgresql://test:test@localhost:5432/nepa_test?schema=public"

# Notification Service Database
NOTIFICATION_SERVICE_DATABASE_URL="postgresql://test:test@localhost:5432/nepa_test?schema=public"

# Document Service Database
DOCUMENT_SERVICE_DATABASE_URL="postgresql://test:test@localhost:5432/nepa_test?schema=public"

# Utility Service Database
UTILITY_SERVICE_DATABASE_URL="postgresql://test:test@localhost:5432/nepa_test?schema=public"

# Payment Service Database
PAYMENT_SERVICE_DATABASE_URL="postgresql://test:test@localhost:5432/nepa_test?schema=public"

# Billing Service Database
BILLING_SERVICE_DATABASE_URL="postgresql://test:test@localhost:5432/nepa_test?schema=public"

# Analytics Service Database
ANALYTICS_SERVICE_DATABASE_URL="postgresql://test:test@localhost:5432/nepa_test?schema=public"

# Webhook Service Database
WEBHOOK_SERVICE_DATABASE_URL="postgresql://test:test@localhost:5432/nepa_test?schema=public"

# Stellar Configuration
STELLAR_NETWORK="testnet"
STELLAR_HORIZON_URL="https://horizon-testnet.stellar.org"

# JWT Configuration
JWT_SECRET="test-secret-key"
JWT_EXPIRES_IN="24h"
REFRESH_TOKEN_EXPIRES_IN="7d"

# Redis Cache Configuration
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
REDIS_CACHE_DB=1
REDIS_KEY_PREFIX=nepa:cache:test:
REDIS_RETRY_DELAY=100
REDIS_MAX_RETRIES=3
REDIS_LAZY_CONNECT=true
REDIS_CLUSTER_ENABLED=false
REDIS_CLUSTER_NODES=[]

# Cache Strategy
CACHE_DEFAULT_TTL=3600
CACHE_MAX_MEMORY=536870912
CACHE_COMPRESSION_THRESHOLD=1024
CACHE_WARMUP_ENABLED=false
CACHE_MONITORING_ENABLED=false
77 changes: 37 additions & 40 deletions .github/workflows/api-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
POSTGRES_USER: test
POSTGRES_DB: nepa_test
options: >-
--health-cmd pg_isready
--health-cmd "pg_isready -U test"
--health-interval 10s
--health-timeout 5s
--health-retries 5
Expand All @@ -46,11 +46,18 @@ jobs:
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: '**/package-lock.json'

- name: Install dependencies
run: |
cd api-testing
npm install
- name: Copy test environment
run: cp .env.test backend/.env

- name: Install dependencies (backend)
run: npm ci
working-directory: backend

- name: Install dependencies (api-testing)
run: npm ci
working-directory: backend/api-testing

- name: Setup K6 for load testing
run: |
Expand All @@ -67,94 +74,84 @@ jobs:
redis-cli -h localhost -p 6379 ping

- name: Run database migrations
run: |
cd ..
npm run prisma:migrate
run: npm run prisma:migrate
working-directory: backend
env:
DATABASE_URL: postgresql://test:test@localhost:5432/nepa_test

- name: Start API server
run: |
npm run dev &
sleep 30
run: npm run dev &
working-directory: backend
env:
DATABASE_URL: postgresql://test:test@localhost:5432/nepa_test
REDIS_URL: redis://localhost:6379

- name: Run unit tests
run: |
cd api-testing
npm run test:unit
run: npm run test:unit
working-directory: backend/api-testing
env:
API_BASE_URL: http://localhost:3000
DATABASE_URL: postgresql://test:test@localhost:5432/nepa_test

- name: Run integration tests
run: |
cd api-testing
npm run test:integration
run: npm run test:integration
working-directory: backend/api-testing
env:
API_BASE_URL: http://localhost:3000
DATABASE_URL: postgresql://test:test@localhost:5432/nepa_test

- name: Run security tests
run: |
cd api-testing
npm run test:security
run: npm run test:security
working-directory: backend/api-testing
env:
API_BASE_URL: http://localhost:3000
DATABASE_URL: postgresql://test:test@localhost:5432/nepa_test

- name: Run contract tests
run: |
cd api-testing
npm run test:contract
run: npm run test:contract
working-directory: backend/api-testing
env:
API_BASE_URL: http://localhost:3000
DATABASE_URL: postgresql://test:test@localhost:5432/nepa_test

- name: Run performance tests
run: |
cd api-testing
npm run test:performance
run: npm run test:performance
working-directory: backend/api-testing
env:
API_BASE_URL: http://localhost:3000
DATABASE_URL: postgresql://test:test@localhost:5432/nepa_test

- name: Run load tests
run: |
cd api-testing
npm run test:load
run: npm run test:load
working-directory: backend/api-testing
env:
API_BASE_URL: http://localhost:3000

- name: Run end-to-end tests
run: |
cd api-testing
npm run test:e2e
run: npm run test:e2e
working-directory: backend/api-testing
env:
API_BASE_URL: http://localhost:3000
DATABASE_URL: postgresql://test:test@localhost:5432/nepa_test

- name: Generate test report
run: |
cd api-testing
npm run test:generate-report
run: npm run test:generate-report
working-directory: backend/api-testing

- name: Upload test reports
uses: actions/upload-artifact@v4
if: always()
with:
name: test-reports
path: api-testing/test-reports/
path: backend/api-testing/test-reports/
retention-days: 30

- name: Upload coverage reports
uses: actions/upload-artifact@v4
if: always()
with:
name: coverage-reports
path: api-testing/coverage/
path: backend/api-testing/coverage/
retention-days: 30

- name: Comment PR with test results
Expand All @@ -163,7 +160,7 @@ jobs:
with:
script: |
const fs = require('fs');
const path = 'api-testing/test-reports';
const path = 'backend/api-testing/test-reports';

if (fs.existsSync(path)) {
const files = fs.readdirSync(path);
Expand Down Expand Up @@ -213,9 +210,9 @@ jobs:

- name: Run security vulnerability scan
run: |
cd api-testing
npm audit --audit-level moderate
npm run test:security-scan
working-directory: backend/api-testing
env:
API_BASE_URL: http://localhost:3000

Expand All @@ -224,5 +221,5 @@ jobs:
if: always()
with:
name: security-scan-results
path: api-testing/security-reports/
path: backend/api-testing/security-reports/
retention-days: 30
46 changes: 40 additions & 6 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
POSTGRES_USER: test
POSTGRES_DB: nepa_test
options: >-
--health-cmd pg_isready
--health-cmd "pg_isready -U test"
--health-interval 10s
--health-timeout 5s
--health-retries 5
Expand Down Expand Up @@ -48,12 +48,15 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: '**/package-lock.json'

- name: Install dependencies
run: npm ci
working-directory: backend

- name: Copy test environment
run: cp .env.test .env
run: cp ../.env.test .env
working-directory: backend

- name: Wait for services to be ready
run: |
Expand All @@ -71,9 +74,11 @@ jobs:

- name: Generate Prisma client
run: npx prisma generate
working-directory: backend

- name: Run database migrations
run: npx prisma migrate deploy
working-directory: backend
env:
DATABASE_URL: postgresql://test:test@localhost:5432/nepa_test

Expand All @@ -84,6 +89,7 @@ jobs:
else
echo "No lint script found, skipping..."
fi
working-directory: backend

- name: Run type checking
run: |
Expand All @@ -93,23 +99,26 @@ jobs:
echo "No type-check script found, running tsc..."
npx tsc --noEmit
fi
working-directory: backend

- name: Run unit tests
run: npm run test:unit -- --coverage --watchAll=false
working-directory: backend
env:
NODE_ENV: test
DATABASE_URL: postgresql://test:test@localhost:5432/nepa_test

- name: Run integration tests
run: npm run test:integration -- --watchAll=false
working-directory: backend
env:
NODE_ENV: test
DATABASE_URL: postgresql://test:test@localhost:5432/nepa_test

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage/lcov.info
file: backend/coverage/lcov.info
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
Expand All @@ -125,12 +134,30 @@ jobs:
with:
node-version: '20.x'
cache: 'npm'
cache-dependency-path: '**/package-lock.json'

- name: Install dependencies
run: npm ci
working-directory: backend

- name: Run security audit
run: npm audit --audit-level=moderate
run: |
npm audit --audit-level=moderate
AUDIT_EXIT=$?
if [ $AUDIT_EXIT -eq 0 ]; then
echo "βœ… No moderate or high vulnerabilities found"
exit 0
elif [ $AUDIT_EXIT -eq 1 ]; then
echo "⚠️ Vulnerabilities found. Attempting to fix..."
npm audit fix || {
echo "❌ Some vulnerabilities cannot be automatically fixed"
echo "Please review manually and update dependencies"
exit 1
}
else
exit $AUDIT_EXIT
fi
working-directory: backend

- name: Run dependency check
run: |
Expand All @@ -153,18 +180,21 @@ jobs:
with:
node-version: '20.x'
cache: 'npm'
cache-dependency-path: '**/package-lock.json'

- name: Install dependencies
run: npm ci
working-directory: backend

- name: Build application
run: npm run build
working-directory: backend

- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: build-files
path: dist/
path: backend/dist/
retention-days: 30

deploy-staging:
Expand Down Expand Up @@ -225,15 +255,19 @@ jobs:
with:
node-version: '20.x'
cache: 'npm'
cache-dependency-path: '**/package-lock.json'

- name: Install dependencies
run: npm ci
working-directory: frontend

- name: Install Playwright
run: npx playwright install --with-deps
working-directory: frontend

- name: Run E2E tests
run: npm run test:e2e
working-directory: frontend
env:
BASE_URL: https://staging.nepa.example.com

Expand All @@ -242,5 +276,5 @@ jobs:
if: failure()
with:
name: playwright-report
path: playwright-report/
path: frontend/playwright-report/
retention-days: 7
Loading
Loading