import { b as Payment, P as Preapproval, f as Preference, R as Refund, h as Customer, p as SubscriptionPayment } from './types-BaOjfcOt.cjs'; import 'zod'; /** * `@ar-agents/mercadopago/testing` — fixtures and a mock client for tests. * * What you get: * * - **Factories** for every shape a user-side test will need: `mockPayment`, * `mockPreapproval`, `mockSubscriptionPayment`, `mockPreference`, * `mockRefund`, `mockCustomer`, `mockWebhookHeaders`. Each accepts a * partial `overrides` object so you only spell the fields your test * actually cares about. * * - **`MockMercadoPagoClient`** — a class with the same surface as * `MercadoPagoClient` but backed by an in-memory store. No network. Its * mutations (createPayment, createPreapproval, etc.) update the store * so a test can do create-then-get without staging fixtures twice. * Read-only methods that don't fit a clean store model (search filters, * pagination edge cases) throw `MockNotImplementedError` — by design, * so you notice when a test wanders into territory that needs MSW or a * real sandbox token. * * - **`mockSignedWebhook`** — produces a `{ body, headers, searchParams }` * bundle whose `x-signature` passes `verifyWebhookSignature` against the * same secret. Test the full webhook stack end-to-end without hand-rolling * the HMAC. * * Why a subpath: the testing helpers are dev-time only and would bloat the * production bundle if exported from the main entry. Imports compile away * cleanly when bundlers tree-shake. * * @example * ```ts * import { MockMercadoPagoClient, mockPayment, mockSignedWebhook } from "@ar-agents/mercadopago/testing"; * * test("approves and stores a payment", async () => { * const mp = new MockMercadoPagoClient(); * mp.seed.payments([mockPayment({ status: "approved", transaction_amount: 1000 })]); * const got = await mp.searchPayments({ status: "approved" }); * expect(got.results).toHaveLength(1); * }); * * test("end-to-end webhook with a verified signature", async () => { * const { body, headers, searchParams } = await mockSignedWebhook({ * topic: "payment", * dataId: "123", * secret: "test-secret", * }); * const ok = await verifyWebhookSignature({ * requestId: headers.get("x-request-id"), * dataId: "123", * signatureHeader: headers.get("x-signature"), * secret: "test-secret", * }); * expect(ok).toBe(true); * }); * ``` */ /** Build a Payment fixture. Sensible defaults for the most common scenario * (an approved $1000 ARS sale with an external_reference). */ declare function mockPayment(overrides?: Partial): Payment; /** Build a Preapproval (recurring subscription) fixture. */ declare function mockPreapproval(overrides?: Partial): Preapproval; /** Build a SubscriptionPayment (single recurring-charge attempt) fixture. */ declare function mockSubscriptionPayment(overrides?: Partial): SubscriptionPayment; /** Build a Preference (Checkout Pro) fixture. */ declare function mockPreference(overrides?: Partial): Preference; /** Build a Refund fixture. */ declare function mockRefund(overrides?: Partial): Refund; /** Build a Customer fixture. */ declare function mockCustomer(overrides?: Partial): Customer; /** Build a `webhookHeaders + searchParams + body` triple for a `payment.created` * topic. Use directly when you don't need a verified signature. */ declare function mockWebhookHeaders(args?: { topic?: string; dataId?: string; requestId?: string; }): { headers: Headers; searchParams: URLSearchParams; body: string; }; /** * Like `mockWebhookHeaders`, but also computes a real HMAC-SHA256 signature * against `secret` so `verifyWebhookSignature` accepts it. Use this in tests * for the full webhook handler stack. */ declare function mockSignedWebhook(args: { topic?: string; dataId?: string; requestId?: string; secret: string; ts?: number; }): Promise<{ headers: Headers; searchParams: URLSearchParams; body: string; }>; /** * Thrown when a mock client method has no in-memory implementation. By design: * if your test relied on the missing path, switch to MSW or a real sandbox * token rather than expanding the mock surface ad-hoc. */ declare class MockNotImplementedError extends Error { constructor(method: string); } /** * In-memory client. Implements the most-commonly-needed read + write paths. * Tests that need long-tail behaviour (search by complex filters, error * injection) should reach for MSW. */ declare class MockMercadoPagoClient { private payments; private preapprovals; private preferences; private refunds; private customers; /** Seed the in-memory store. */ seed: { payments: (xs: Payment[]) => void; preapprovals: (xs: Preapproval[]) => void; preferences: (xs: Preference[]) => void; refunds: (xs: Refund[]) => void; customers: (xs: Customer[]) => void; }; getPayment(id: string): Promise; createPayment(params: Partial): Promise; searchPayments(filter?: { status?: string; externalReference?: string; }): Promise<{ paging: { total: number; limit: number; offset: number; }; results: { [x: string]: unknown; id: string; status: string; transaction_amount: number; currency_id: string; status_detail?: string | null | undefined; date_created?: string | null | undefined; date_approved?: string | null | undefined; date_last_updated?: string | null | undefined; installments?: number | null | undefined; payment_method_id?: string | null | undefined; payment_type_id?: string | null | undefined; external_reference?: string | null | undefined; description?: string | null | undefined; payer?: { [x: string]: unknown; id?: string | number | undefined; email?: string | null | undefined; identification?: { type?: string | null | undefined; number?: string | null | undefined; } | null | undefined; } | undefined; transaction_details?: { [x: string]: unknown; net_received_amount?: number | null | undefined; total_paid_amount?: number | null | undefined; installment_amount?: number | null | undefined; } | undefined; }[]; }>; cancelPayment(id: string): Promise; getPreapproval(id: string): Promise; createPreapproval(params: Partial): Promise; cancelPreapproval(id: string): Promise; pausePreapproval(id: string): Promise; resumePreapproval(id: string): Promise; createRefund(params: { payment_id: string; amount?: number; }): Promise; getCustomer(id: string): Promise; createCustomer(params: Partial): Promise; getPreference(id: string): Promise; createPreference(params: Partial): Promise; [key: string]: any; } export { MockMercadoPagoClient, MockNotImplementedError, mockCustomer, mockPayment, mockPreapproval, mockPreference, mockRefund, mockSignedWebhook, mockSubscriptionPayment, mockWebhookHeaders };