Skip to content

test: add unit tests for PaymentsService and MaintenanceWorker #424

@Mahmoud-s-Khedr

Description

@Mahmoud-s-Khedr

Problem

PaymentsService and MaintenanceWorker contain critical business logic (invoice lifecycle, fee calculations, scheduled invoice polling) but have very low or zero test coverage:

  • src/services/payments-service.ts — 8% statement coverage
  • src/app/maintenance-worker.ts — 0% coverage

Proposed Solution

Add unit tests for both modules using existing patterns (Mocha + Chai + Sinon):

payments-service.spec.ts (~29 tests):

  • getPendingInvoices() — delegation and error propagation
  • getInvoiceFromPaymentsProcessor() — string vs Invoice input handling, verifyURL logic
  • createInvoice() — transaction lifecycle (begin/commit/rollback), field mapping
  • updateInvoice() / updateInvoiceStatus() — delegation to repository
  • confirmInvoice() — validation guards, SATS/BTC/MSATS unit conversions, admission fee schedule filtering with pubkey whitelists, user admission on threshold met, transaction rollback on error
  • sendInvoiceUpdateNotification() — event construction, MSATS->SATS conversion, error logging in pipeline

maintenance-worker.spec.ts (~17 tests):

  • Signal handler registration
  • Interval scheduling
  • Skips processing when payments disabled
  • Invoice polling loop with per-invoice error resilience
  • Status change detection (PENDING -> COMPLETED)
  • amountRequested fallback for amountPaid via mergeDeepLeft
  • close(), onError(), onExit() behavior

Impact

Raises overall unit test coverage from ~50% to ~55% statements. Both files reach 100% statement/function coverage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions