Test utilities for the Sapliy Fintech Ecosystem — mock servers, fixtures, and assertion helpers.
npm install @sapliyio/fintech-testing --save-dev- Mock Servers: MSW-based mock handlers for all API endpoints
- Fixtures: Factory functions for creating test data
- Assertions: Custom helpers for webhook signatures, ledger balances, etc.
- Utilities: Helper functions for retries, test IDs, and more
import { setupTestServer } from '@sapliyio/fintech-testing/mocks';
// In your test setup file (e.g., vitest.setup.ts)
setupTestServer();import {
createPaymentIntent,
createZone,
zoneFactory
} from '@sapliyio/fintech-testing/fixtures';
// Create a payment intent
const intent = createPaymentIntent({ amount: 5000, currency: 'EUR' });
// Create a zone with custom options
const zone = zoneFactory.build({ mode: 'live', name: 'Production' });import {
verifyWebhookSignature,
generateWebhookSignature
} from '@sapliyio/fintech-testing';
// Generate a signature for testing
const payload = JSON.stringify({ type: 'payment.succeeded', data: {} });
const signature = generateWebhookSignature(payload, 'whsec_test_key');
// Verify in your tests
const result = verifyWebhookSignature(payload, signature, 'whsec_test_key');
console.log(result.valid); // trueimport { retryWithBackoff, createMockEvent } from '@sapliyio/fintech-testing';
// Retry flaky operations
const result = await retryWithBackoff(
() => fetchSomething(),
{ maxRetries: 3, initialDelay: 100 }
);
// Create mock events
const event = createMockEvent('checkout.completed', {
orderId: 'order_123'
});paymentHandlers— Payment intents, charges, refundszoneHandlers— Zone CRUD operationsauthHandlers— API key verificationeventHandlers— Event emission and listingallHandlers— All handlers combined
paymentIntentFactory.build(overrides)— Create PaymentIntentchargeFactory.build(overrides)— Create ChargerefundFactory.build(overrides)— Create RefundzoneFactory.build(overrides)— Create ZoneapiKeyFactory.build(overrides)— Create ApiKeycreateZonePair(name)— Create test/live zone pair
verifyWebhookSignature(payload, signature, secret)assertLedgerBalance(entries, expectedBalance)assertHasScopes(keyScopes, requiredScopes)assertIdempotencyKey(key)
MIT © Sapliy