Skip to content

test: Unit & integration tests for PaystackGateway #36

Description

@teesofttech

Overview

Add a complete unit and integration test suite for PaystackGateway.

Gateway Details

  • Class: PaystackGateway
  • Auth: Bearer token (SecretKey)
  • Base URL: https://api.paystack.co
  • Currency: NGN (amount x100 kobo)
  • Enum: PaymentGatewayType.Paystack = 2

Unit Tests (mocked HTTP)

Constructor

  • Throws InvalidOperationException when SecretKey is null/empty
  • Constructs successfully with a valid SecretKey

CreatePaymentAsync

  • Posts to /transaction/initialize with amount in kobo
  • Sets Authorization: Bearer header
  • Returns PaymentResponse.Success=true and CheckoutUrl on 200 success response
  • Returns PaymentResponse.Success=false on API error
  • Handles HttpRequestException gracefully

VerifyPaymentAsync

  • Sends GET /transaction/verify/{reference}
  • Returns IsSuccessful=true when data.status=success
  • Returns IsSuccessful=false when data.status=failed

RefundPaymentAsync

  • Posts to /refund with correct body
  • Returns RefundResponse.IsSuccessful=true on success

Integration Tests

Requires PAYSTACK_SECRET_KEY env var (sandbox key)

  • CreatePaymentAsync returns a real Paystack checkout URL
  • VerifyPaymentAsync returns correct status for a known sandbox reference

Files to Create

  • PayBridge.SDK.Test/Unit/PaystackGatewayTests.cs
  • PayBridge.SDK.Test/Integration/PaystackIntegrationTests.cs

Acceptance Criteria

  • All unit tests pass with zero live HTTP calls
  • Integration tests decorated with [Trait("Category", "Integration")] and skip when env var is absent
  • Code coverage >= 80% for PaystackGateway.cs

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: gatewaysPayment gateway integrations and provider behaviorarea: testingAutomated test architecture and coveragepriority: P1High priority; should be addressed nexttestingTest coverage and test suite work

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions