@vulog/aima-billing
Version:
Invoice management, credits, wallets, and refunds.
63 lines (54 loc) • 1.83 kB
text/typescript
import { describe, test, expect, vi, beforeEach, afterEach } from 'vitest';
import { PatchAction } from '@vulog/aima-core';
import { updateWallet, Paths } from './updateWallet';
import { Client } from '@vulog/aima-client';
describe('updateWallet', () => {
const patchMock = vi.fn();
const client = {
patch: patchMock,
clientOptions: {
fleetId: 'FLEET_ID',
},
} as unknown as Client;
beforeEach(() => {
vi.clearAllMocks();
});
test('should return invalid args', async () => {
const walletId = 'WALLET_ID';
const actions = [
{
op: 'invalid-op',
path: '/availableAmount',
value: '100',
},
];
await expect(updateWallet(client, walletId, actions as PatchAction<Paths>[])).rejects.toThrowError();
});
test('should return invalid args with too much entries in the array', async () => {
const walletId = 'WALLET_ID';
const actions = [
{
op: 'replace',
path: '/availableAmount',
value: '100',
},
{
op: 'replace',
path: '/percentage',
value: '20.50',
},
];
await expect(updateWallet(client, walletId, actions as PatchAction<Paths>[])).rejects.toThrowError();
});
test('should update wallet successfully', async () => {
const walletId = '550e8400-e29b-41d4-a716-446655440000';
const actions = [
{
op: 'replace' as const,
path: '/availableAmount' as const,
value: '100',
},
];
await expect(updateWallet(client, walletId, actions)).resolves.toBeUndefined();
});
});