@codepunter-labs/mock-moolre
v0.2.0
Published
TODO
Readme
@codepunter-labs/mock-moolre
Mock SDK for Moolre API. Provides fully-typed mock implementations for testing Moolre account, transfers, payments, and SMS integrations without making real API calls.
Installation
npm install @codepunter-labs/mock-moolreFeatures
- Account: Create wallets, update accounts, check balance
- Transfers: Send transfers
- Payments: Process mobile money payments
- SMS: Send SMS, generate and verify OTP
- Type-safe: Full TypeScript support with accurate API types
- Test Framework Agnostic: Works with Jest, Vitest, and other spy-based frameworks
Repository
- GitHub: https://github.com/DERRICK-TORKORNOO/mock-sdks/tree/main/packages/mock-moolre
- Source Code: src/
- Tests: tests/
Usage
Basic Setup
import { vi } from 'vitest';
import { createMockMoolre } from '@codepunter-labs/mock-moolre';
const moolre = createMockMoolre({ spy: vi.fn });Using with Jest
import { createMockMoolre } from '@codepunter-labs/mock-moolre';
const moolre = createMockMoolre({ spy: jest.fn });Example: Create Wallet
// Default behavior - returns realistic mock data
const result = await moolre.createWallet({
accountname: 'My Business LTD',
api: true,
callback: 'https://example.com/webhook'
});Example: Send Transfer
const result = await moolre.sendTransfer({
accountnumber: '100000157291',
amount: 100,
recipient_account: '9207067319',
recipient_bank: '000013',
recipient_name: 'John Doe'
});Example: Override Mock Response
import { makeWallet } from '@codepunter-labs/mock-moolre';
moolre.createWallet.mockResolvedValue({
status: 1,
code: 'WC02',
message: 'Wallet Created Successfully',
data: makeWallet({ accountname: 'Test Business' }),
go: null
});Example: Error Simulation
import { MockErrors } from '@codepunter-labs/mock-core';
moolre.sendTransfer.mockRejectedValue(
MockErrors.badRequest('Insufficient balance')
);API Reference
MockMoolre
createWallet(request)- Create walletupdateAccount(request)- Update accountgetBalance()- Get account balancesendTransfer(request)- Send transferprocessMobileMoneyPayment(request)- Process mobile money paymentsendSms(request)- Send SMSgenerateOtp(request)- Generate OTPverifyOtp(request)- Verify OTP
Fixture Factories
makeWallet(options?)- Create walletmakeBalanceResponse(options?)- Create balance responsemakeTransferResponse(options?)- Create transfer responsemakePaymentResponse(options?)- Create payment responsemakeSmsResponse(options?)- Create SMS responsemakeOtpResponse(options?)- Create OTP responsemakeVerifyOtpResponse(options?)- Create OTP verification response
Testing Patterns
Test Success Path
test('should create wallet successfully', async () => {
const moolre = createMockMoolre({ spy: vi.fn });
const result = await moolre.createWallet(request);
expect(result.status).toBe(1);
expect(result.message).toBe('Wallet Created Successfully');
});Test Error Handling
test('should handle insufficient balance error', async () => {
const moolre = createMockMoolre({ spy: vi.fn });
moolre.sendTransfer.mockRejectedValue(
MoolreErrors.insufficientBalance()
);
await expect(moolre.sendTransfer(request)).rejects.toMatchObject({ status: 0, code: 'TRF002' });
});Test with Custom Data
test('should use custom wallet name', async () => {
const moolre = createMockMoolre({ spy: vi.fn });
moolre.createWallet.mockResolvedValue({
status: 1,
code: 'WC02',
message: 'Wallet Created Successfully',
data: makeWallet({ accountname: 'Custom Business' }),
go: null
});
const result = await moolre.createWallet(request);
expect(result.data.accountname).toBe('Custom Business');
});License
MIT
