UNPKG

@vulog/aima-billing

Version:

Invoice management, credits, wallets, and refunds.

51 lines (43 loc) 1.46 kB
import { describe, test, expect, vi, beforeEach, afterEach } from 'vitest'; import { refund } from './refund'; import { Client } from '@vulog/aima-client'; describe('refund', () => { const postMock = vi.fn(); const client = { post: postMock, clientOptions: { fleetId: 'FLEET_ID', }, } as unknown as Client; beforeEach(() => { vi.clearAllMocks(); }); test('should return invalid args', async () => { const payload = { invoiceId: 'INVOICE_ID', amount: -10, // Invalid amount }; // expect to throw error if invalid args are provided await expect(refund(client, payload)).rejects.toThrow('Invalid args'); }); test('should process refund successfully', async () => { const payload = { invoiceId: 'INVOICE_ID', amount: 50, note: 'Customer requested refund', paymentIntentPspReference: undefined, }; postMock.mockResolvedValueOnce({ data: undefined, }); const result = await refund(client, payload); expect(result).toBeUndefined(); expect(postMock).toHaveBeenCalledWith( `/boapi/proxy/billing/fleets/${client.clientOptions.fleetId}/invoices/${payload.invoiceId}/refund`, { amount: 50, note: 'Customer requested refund', } ); }); });