McTaba Labs logo
Software EngineeringThe WhiteboardProjectsEventsMasterclassesWebinarsLearn
Book Call

500+ developers already in the community

Get answers, find accountability partners, and stay ahead

Join Discord →
McTaba Labs logo

Educating 1 million students in tech by 2030.

Programs

  • HighSchool Graduates Launchpad
  • AI & Business Automation
  • Corporate Training
  • McTaba Story & Mission
  • Full-Stack Curriculum
  • Course Pricing & Plans
  • Frequently Asked Questions

Resources

  • Join Discord Community
  • Tech Events in Nairobi
  • Masterclasses
  • Free Resources
  • Learn
  • Campus
  • Africa Tech Talent Report
  • Partner With Us
  • Start a Project
  • Our Work

Contact Us

  • 124 Manyani East Road, Lavington, Nairobi
  • +254727795603
  • Book a Discovery Call

Office Hours:

Mon-Fri: 9am - 2pm EAT

Sat: 10am - 12pm EAT

© 2027 McTaba Labs - A product of Edtech Industries. All rights reserved.

Privacy PolicyTerms of ServiceRefund Policy
  1. Learn
  2. Paystack for African Developers
  3. Test Coverage Targets for Payment Code
Bonaventure OgetoBy Bonaventure Ogeto|Updated July 22, 2026

Test Coverage Targets for Payment Code

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%.

In this article

  1. 1. Payment Code Coverage Target Matrix
  2. 2. Setting Coverage Thresholds in Jest
  3. 3. Learn More

Payment Code Coverage Target Matrix

Code ComponentTarget CoverageWhy
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

Setting Coverage Thresholds in Jest

// 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.

Learn More

This guide is part of the Paystack testing guide.

Sign up for the McTaba newsletter

Key Takeaways

  • ✓Webhook handler business logic should have 100% branch coverage — every code path that handles money must be tested.
  • ✓Amount and commission calculation functions need 100% branch coverage, including edge cases (0 amount, max amount, rounding).
  • ✓Checkout initiation code (API call construction) should be at 90%+ coverage.
  • ✓Error handling paths (network errors, 5xx from Paystack, invalid response format) need dedicated tests — do not rely on the happy path to cover these.
  • ✓Frontend payment UI can have 60-70% coverage — E2E tests cover the rest.
  • ✓Set coverage thresholds in your test config (Jest coverageThreshold, pytest-cov --fail-under) to block low-coverage merges.

Frequently Asked Questions

Is 100% coverage achievable for a webhook handler?
Yes — webhook handlers are pure logic functions with a finite number of input combinations. Write a test for each event type you handle (charge.success, charge.failed, etc.), each branch condition (metadata missing, order not found, duplicate reference), and each error case. 100% branch coverage is realistic and worth the effort for money-moving code.
Does high test coverage mean my payment code is secure?
Coverage measures which code paths are tested, not how well they are tested. 100% coverage with poor assertions means nothing. A 90% covered webhook handler with rigorous assertions (testing that the right DB columns update, the right amounts are recorded) is better than 100% coverage with "expect(result).toBeTruthy()" everywhere.
Should I measure line coverage or branch coverage for payment code?
Branch coverage is more meaningful for payment code. A function with an if/else might have 100% line coverage if tests exercise both the if and else code, but if you only test one branch, you have 50% branch coverage. Branch coverage catches untested conditional logic that line coverage misses.
What is a good coverage target for a first-time payment integration?
Start with 80% statement coverage globally, and set per-file 100% for webhook handler and amount calculation files. As you add more tests, raise the global threshold. The key is to start with thresholds and enforce them in CI — even imperfect targets are better than no targets.

Learn Paystack Integration

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

Not ready? Create Free Account

Keep reading

Testing Paystack Integrations: The Complete Guide

A complete guide to testing Paystack integrations at every level: test mode, test cards, unit tests with mocks, integration tests, end-to-end flows with Playwright, webhook simulation, contract testing, CI pipelines, staging environments, load testing, and coverage targets for payment code.

Read more

Simulating Declined Cards on Paystack

A card decline is one of the most common failure states in a payment flow, and your application must handle it gracefully. This guide shows how to simulate specific card declines in Paystack test mode and how to verify your decline handling code works correctly.

Read more

Mocking the Paystack API in PHPUnit

PHPUnit tests for Paystack integrations in Laravel or PHP can run without any network calls using Laravel's Http::fake() or Mockery. This guide shows how to mock Paystack responses, test webhook handlers, and verify your payment logic in isolation.

Read more

Contract Testing Your Paystack Webhook Handler

Contract testing verifies that your webhook handler correctly handles the exact payload structure Paystack sends. If Paystack adds or renames a field, contract tests catch the mismatch before it reaches production. This guide shows how to write contract tests for Paystack webhook events.

Read more

Paystack Mixed Content and HTTPS Errors

Your site is served over HTTP but Paystack scripts load over HTTPS. Modern browsers block this mix. The fix is to serve your entire site over HTTPS.

Read more

Explore related topics

M-Pesa & African Stack

M-Pesa Daraja API tutorials, USSD development, and WhatsApp Business API guides. The African Stack that global bootcamps do not teach.

Learn to Code in Kenya

Everything a Kenyan needs to know before writing their first line of code. Career paths, real costs, hardware requirements, and honest answers about what it takes.

Learning to Code

Roadmaps, language guides, and practical advice for learning to code and launching a programming career.

Breaking Into Tech

Practical, no-nonsense guides for anyone looking to start or change their career in tech. From choosing your first language to acing interviews.

The African Stack: Skills for This Market

The skills that make Kenyan developers hard to replace: M-Pesa, USSD, WhatsApp, fintech, and building for the African market.

Bonaventure Ogeto

Bonaventure Ogeto

Founder, McTaba Labs

Bonaventure is the founder of McTaba Labs, a coding bootcamp in Nairobi, Kenya. He has spent years building products for the African market and mentoring the next generation of developers across the continent.