test: add nock-based unit coverage for PluggyPaymentsClient#167
Open
Gabrielpanga wants to merge 1 commit into
Open
test: add nock-based unit coverage for PluggyPaymentsClient#167Gabrielpanga wants to merge 1 commit into
Gabrielpanga wants to merge 1 commit into
Conversation
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>
cernadasjuan
approved these changes
May 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
tests/payments/— 10 spec files, 43 tests, one per public method ofPluggyPaymentsClient. Mocks/auth+ the target endpoint vianock, 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:
PluggyPaymentsClienttalks 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)
paymentRequests.test.tscreatePaymentRequest,fetchPaymentRequest,fetchPaymentRequests,deletePaymentRequestpaymentIntents.test.tscreatePaymentIntent,fetchPaymentIntent,fetchPaymentIntentspaymentCustomers.test.tscreatePaymentCustomer,fetchPaymentCustomer,fetchPaymentCustomers,updatePaymentCustomer,deletePaymentCustomerpaymentRecipients.test.tscreatePaymentRecipient,fetchPaymentRecipient,fetchPaymentRecipients,updatePaymentRecipient,deletePaymentRecipientpaymentInstitutions.test.tsfetchPaymentInstitution,fetchPaymentInstitutions(withnamefilter)bulkPayments.test.tscreateBulkPayment,fetchBulkPayment,fetchBulkPayments,deleteBulkPaymentsmartAccounts.test.tscreateSmartAccount,fetchSmartAccount,fetchSmartAccountBalance,fetchSmartAccountsscheduledPayments.test.tsfetchScheduledPayments,fetchScheduledPayment,cancelScheduledPayment,cancelScheduledPaymentsautomaticPix.test.tscreatePaymentRequestPixAutomatico,scheduleAutomaticPixPayment,retryAutomaticPixPayment,fetchAutomaticPixPayments,fetchAutomaticPixPayment,cancelAutomaticPixPayment,cancelAutomaticPixAuthorizationsmartTransfers.test.tsfetchSmartTransferPreauthorizations,createSmartTransferPreauthorization,fetchSmartTransferPreauthorization,createSmartTransferPayment,fetchSmartTransferPaymentHelper
tests/payments/utils.tsfactors shared boilerplate:createPaymentsClient()— wiressetupAuth()and returns a fresh client.mockAs<T>(partial)— minimal-but-typed mock objects (same pattern as the existingtests/transactions.test.ts).Test plan
pnpm test— 54/54 passing (11 pre-existing + 43 new).pnpm build— clean.🤖 Generated with Claude Code