@sapliyio/fintech-testing
v1.0.0
Published
Test utilities for Sapliy Fintech Ecosystem - mock servers, fixtures, and assertions
Readme
Sapliy Fintech Testing
Test utilities for the Sapliy Fintech Ecosystem — mock servers, fixtures, and assertion helpers.
Installation
npm install @sapliyio/fintech-testing --save-devFeatures
- 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
Quick Start
Setting Up Mock Server
import { setupTestServer } from '@sapliyio/fintech-testing/mocks';
// In your test setup file (e.g., vitest.setup.ts)
setupTestServer();Using Fixtures
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' });Webhook Signature Verification
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); // trueOther Utilities
import { 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'
});API Reference
Mock Handlers
paymentHandlers— Payment intents, charges, refundszoneHandlers— Zone CRUD operationsauthHandlers— API key verificationeventHandlers— Event emission and listingallHandlers— All handlers combined
Fixtures
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
Assertions
verifyWebhookSignature(payload, signature, secret)assertLedgerBalance(entries, expectedBalance)assertHasScopes(keyScopes, requiredScopes)assertIdempotencyKey(key)
License
MIT © Sapliy
