Configure your GitHub Actions CI pipeline with two jobs: (1) unit-tests — runs fast, no network, uses mocked Paystack; (2) integration-tests — uses PAYSTACK_TEST_KEY secret, calls real Paystack test API, runs only on PRs to main. Add a coverage step that fails the workflow if coverage drops below threshold. Never store live Paystack keys in CI — test keys only.
# .github/workflows/payment-tests.yml
name: Payment Tests
on:
push:
branches: ['*']
pull_request:
branches: [main]
jobs:
unit-tests:
name: Unit Tests (fast, no network)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- run: npm ci
- run: npm test -- --testPathPattern="unit|webhook" --coverage
env:
PAYSTACK_SECRET_KEY: sk_test_fake_for_unit_tests
NODE_ENV: test
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage/
integration-tests:
name: Integration Tests (real Paystack test API)
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
services:
postgres:
image: postgres:16
env:
POSTGRES_PASSWORD: testpass
POSTGRES_DB: testdb
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- run: npm ci
- run: npm run db:migrate:test
env:
DATABASE_URL: postgres://postgres:testpass@localhost:5432/testdb
- run: npm test -- --testPathPattern="integration"
env:
PAYSTACK_SECRET_KEY: ${{ secrets.PAYSTACK_TEST_KEY }}
DATABASE_URL: postgres://postgres:testpass@localhost:5432/testdb
NODE_ENV: test
This guide is part of the Paystack testing guide.
KES 2,999
The definitive guide to building payment systems with Paystack — from your first transaction to production-grade payment infrastructure across Africa. 9 modules, 47 lessons. Free preview available.
Start Paystack Course