Payment code coverage targets: webhook handler (critical business logic) → 100% branch coverage; amount/commission calculation functions → 100% branch coverage; checkout initiation → 90%+; error handling paths → 80%+; frontend checkout UI → 60-70% is acceptable (covered by E2E tests). Use Istanbul/nyc (JS) or coverage.py (Python) to measure. Block merges if webhook handler coverage drops below 90%.
| Code Component | Target Coverage | Why |
|---|---|---|
| Webhook signature validation | 100% | Security-critical — missing this allows fake events |
| Webhook event routing (charge.success, etc.) | 100% branches | Each event type triggers different business logic |
| Order fulfillment after payment | 100% branches | Bugs here mean unfulfilled orders or double fulfillment |
| Amount/commission calculations | 100% branches | Rounding bugs cost money — cover all number edge cases |
| Checkout API call construction | 90%+ | Ensure correct parameters are sent to Paystack |
| Error handling (network, 5xx) | 80%+ | Prevent silent failures and 500 responses to customers |
| Idempotency checks | 100% | Duplicate processing = financial data corruption |
| Transfer payout logic | 90%+ | Wrong recipient or amount = real financial loss |
| Frontend checkout UI | 60-70% | E2E tests cover the full user flow |
// jest.config.js
module.exports = {
collectCoverage: true,
coverageDirectory: 'coverage',
collectCoverageFrom: [
'src/**/*.{js,ts}',
'!src/**/*.test.{js,ts}',
'!src/types/**',
],
coverageThreshold: {
// Global minimum
global: {
branches: 80,
functions: 85,
lines: 85,
statements: 85,
},
// Per-file minimums for critical payment code
'./src/webhooks/paystack-handler.js': {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
},
'./src/payments/fulfillment.js': {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
},
'./src/payments/calculations.js': {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
},
},
};
Get weekly developer tips
Join 25,000+ developers. Practical guides, job tips, and new content — straight to your inbox.
No spam. Unsubscribe anytime.
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