Skip to content

test: add nock-based unit coverage for PluggyPaymentsClient#167

Open
Gabrielpanga wants to merge 1 commit into
masterfrom
test/payments-client-unit-coverage
Open

test: add nock-based unit coverage for PluggyPaymentsClient#167
Gabrielpanga wants to merge 1 commit into
masterfrom
test/payments-client-unit-coverage

Conversation

@Gabrielpanga
Copy link
Copy Markdown
Member

Summary

Adds tests/payments/ — 10 spec files, 43 tests, one per public method of PluggyPaymentsClient. Mocks /auth + the target endpoint via nock, then asserts the SDK builds the right HTTP request (method, path, query, body) and parses the response.

Why nock-only (no real-API integration)

We agreed off-PR: PluggyPaymentsClient talks to live PIX rails / BACEN. Even sandbox-like CRUD on customers and recipients can have side effects, and a real-API integration test that creates payment intents is unacceptable risk. The aggregation suite (tests/integration/, separate PR) runs against the real sandbox connector. Payments stays off the wire — these tests cover request/response shape without ever leaving the test process.

Coverage (1:1 with public methods)

Spec Methods covered
paymentRequests.test.ts createPaymentRequest, fetchPaymentRequest, fetchPaymentRequests, deletePaymentRequest
paymentIntents.test.ts createPaymentIntent, fetchPaymentIntent, fetchPaymentIntents
paymentCustomers.test.ts createPaymentCustomer, fetchPaymentCustomer, fetchPaymentCustomers, updatePaymentCustomer, deletePaymentCustomer
paymentRecipients.test.ts createPaymentRecipient, fetchPaymentRecipient, fetchPaymentRecipients, updatePaymentRecipient, deletePaymentRecipient
paymentInstitutions.test.ts fetchPaymentInstitution, fetchPaymentInstitutions (with name filter)
bulkPayments.test.ts createBulkPayment, fetchBulkPayment, fetchBulkPayments, deleteBulkPayment
smartAccounts.test.ts createSmartAccount, fetchSmartAccount, fetchSmartAccountBalance, fetchSmartAccounts
scheduledPayments.test.ts fetchScheduledPayments, fetchScheduledPayment, cancelScheduledPayment, cancelScheduledPayments
automaticPix.test.ts createPaymentRequestPixAutomatico, scheduleAutomaticPixPayment, retryAutomaticPixPayment, fetchAutomaticPixPayments, fetchAutomaticPixPayment, cancelAutomaticPixPayment, cancelAutomaticPixAuthorization
smartTransfers.test.ts fetchSmartTransferPreauthorizations, createSmartTransferPreauthorization, fetchSmartTransferPreauthorization, createSmartTransferPayment, fetchSmartTransferPayment

Helper

tests/payments/utils.ts factors shared boilerplate:

  • createPaymentsClient() — wires setupAuth() and returns a fresh client.
  • mockAs<T>(partial) — minimal-but-typed mock objects (same pattern as the existing tests/transactions.test.ts).

Test plan

  • pnpm test54/54 passing (11 pre-existing + 43 new).
  • pnpm build — clean.

🤖 Generated with Claude Code

Adds tests/payments/ with one spec per domain, mirroring the structure
of tests/transactions.test.ts. Each test mocks /auth (via the shared
setupAuth helper) and then asserts that the SDK builds the right HTTP
request — method, path, query, body — and parses the response.

Why nock-only and not real-API integration tests: PluggyPaymentsClient
talks to live PIX rails and BACEN. Even sandbox-like CRUD on customers /
recipients can have side effects, and a test that fires a real payment
intent is unacceptable risk. The aggregation suite (tests/integration/)
runs against the real sandbox connector; payments stays off the wire.

Coverage (10 spec files, 43 tests, 1:1 with public methods on
PluggyPaymentsClient):
- paymentRequests:  create / fetch / list / delete
- paymentIntents:   create / fetch / list
- paymentCustomers: create / fetch / list / update / delete
- paymentRecipients: create / fetch / list / update / delete
- paymentInstitutions: fetch / list (with name filter)
- bulkPayments:     create / fetch / list / delete
- smartAccounts:    create / fetch / balance / list
- scheduledPayments: list / get / cancel-one / cancel-all
- automaticPix:     createRequest / schedule / retry / list /
                    get / cancel / cancel-authorization
- smartTransfers:   preauth CRUD + payments create/get

tests/payments/utils.ts factors out the shared boilerplate: a
createPaymentsClient() that wires setupAuth + a fresh client, and a
mockAs<T>() helper for minimal-but-typed mock responses (same pattern
as the existing transactions tests).

pnpm test now 54/54 (was 11/11): 11 pre-existing + 43 new.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants