@codepunter-labs/mock-arkesel
v0.2.0
Published
TODO
Readme
@codepunter-labs/mock-arkesel
Mock SDK for Arkesel API. Provides fully-typed mock implementations for testing Arkesel SMS, OTP, Voice, and other integrations without making real API calls.
Installation
npm install @codepunter-labs/mock-arkeselFeatures
- SMS V2: Send SMS, get SMS details
- OTP: Generate and verify one-time passwords
- Voice: Send voice messages
- Balance: Check account balance
- Contact Groups: Create and manage contact groups
- 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-arkesel
- Source Code: src/
- Tests: tests/
Usage
Basic Setup
import { vi } from 'vitest';
import { createMockArkesel } from '@codepunter-labs/mock-arkesel';
const arkesel = createMockArkesel({ spy: vi.fn });Using with Jest
import { createMockArkesel } from '@codepunter-labs/mock-arkesel';
const arkesel = createMockArkesel({ spy: jest.fn });Example: Send SMS
// Default behavior - returns realistic mock data
const result = await arkesel.sendSms({
sender: 'Arkesel',
message: 'Hello world',
recipients: ['233544919953']
});Example: Generate OTP
const result = await arkesel.generateOtp({
recipient: '233544919953',
expiry: 300,
length: 6
});Example: Override Mock Response
import { makeSendSmsResponse } from '@codepunter-labs/mock-arkesel';
arkesel.sendSms.mockResolvedValue({
status: 'success',
data: makeSendSmsResponse()
});Example: Error Simulation
import { ArkeselErrors } from '@codepunter-labs/mock-arkesel';
arkesel.sendSms.mockRejectedValue(
ArkeselErrors.invalidPhoneNumber()
);API Reference
MockArkesel
| Method | Description | Source |
|--------|-------------|--------|
| sendSms(request) | Send SMS | mock-arkesel.ts |
| getSmsDetails(smsId) | Get SMS details | mock-arkesel.ts |
| generateOtp(request) | Generate OTP | mock-arkesel.ts |
| verifyOtp(request) | Verify OTP | mock-arkesel.ts |
| sendVoice(request) | Send voice message | mock-arkesel.ts |
| getBalance() | Get account balance | mock-arkesel.ts |
| createContactGroup(request) | Create contact group | mock-arkesel.ts |
| addContactsToGroup(request) | Add contacts to group | mock-arkesel.ts |
Fixture Factories
| Factory | Description | Source |
|---------|-------------|--------|
| makeSmsRecipientResult(options?) | Create SMS recipient result | fixtures.ts |
| makeSendSmsResponse(options?) | Create SMS response | fixtures.ts |
| makeSmsDetails(options?) | Create SMS details | fixtures.ts |
| makeGenerateOtpResponse(options?) | Create OTP response | fixtures.ts |
| makeVerifyOtpResponse(options?) | Create OTP verification response | fixtures.ts |
| makeSendVoiceResponse(options?) | Create voice response | fixtures.ts |
| makeBalanceResponse(options?) | Create balance response | fixtures.ts |
| makeContactGroup(options?) | Create contact group | fixtures.ts |
| makeAddContactsToGroupResponse(options?) | Create add contacts response | fixtures.ts |
Error Factories
| Error | Description | Source |
|-------|-------------|--------|
| ArkeselErrors.invalidPhoneNumber() | Invalid phone number error | errors.ts |
| ArkeselErrors.insufficientBalance() | Insufficient balance error | errors.ts |
| ArkeselErrors.otpExpired() | OTP expired error | errors.ts |
| ArkeselErrors.invalidOtp() | Invalid OTP error | errors.ts |
Testing Patterns
Test Success Path
test('should send SMS successfully', async () => {
const arkesel = createMockArkesel({ spy: vi.fn });
const result = await arkesel.sendSms(request);
expect(result.status).toBe('success');
expect(result.data.recipients).toHaveLength(1);
});Test Error Handling
test('should handle invalid phone number error', async () => {
const arkesel = createMockArkesel({ spy: vi.fn });
arkesel.sendSms.mockRejectedValue(
ArkeselErrors.invalidPhoneNumber()
);
await expect(arkesel.sendSms(request)).rejects.toMatchObject({ message: /Invalid phone number/ });
});Test with Custom Data
test('should use custom OTP expiry', async () => {
const arkesel = createMockArkesel({ spy: vi.fn });
arkesel.generateOtp.mockResolvedValue({
status: 'success',
data: makeGenerateOtpResponse({ expiry: 600 })
});
const result = await arkesel.generateOtp(request);
expect(result.data.expiry).toBe(600);
});License
MIT
