import { describe, test, expect, vi, beforeEach } from 'vitest';
import { Client } from '@vulog/aima-client';

import { retryPayment } from './retry-payment';
import { Invoice } from './types';

describe('retryPayment', () => {
    const postMock = vi.fn();
    const client = {
        post: postMock,
        clientOptions: {
            fleetId: 'FLEET_ID',
        },
    } as unknown as Client;

    const invoiceId = '550e8400-e29b-41d4-a716-446655440000';

    beforeEach(() => {
        vi.clearAllMocks();
    });

    test('should return invalid args', async () => {
        await expect(retryPayment(client, 'invalid-invoice-id')).rejects.toThrow('Invalid args');
    });

    test('should retry payment successfully', async () => {
        const invoice = { id: invoiceId, invoicesStatus: 'PENDING' } as Invoice;

        postMock.mockResolvedValueOnce({
            data: invoice,
        });

        const result = await retryPayment(client, invoiceId);

        expect(result).toEqual(invoice);
        expect(postMock).toHaveBeenCalledWith(
            `/boapi/proxy/user/billing/fleets/${client.clientOptions.fleetId}/invoices/${invoiceId}/retry-payment`,
            {}
        );
    });
});
