import { vi, describe, expect, it, beforeAll } from 'vitest';
import { createWrapper } from 'app/test/vitest/helper';
import InvoiceInVat from 'src/pages/InvoiceIn/Card/InvoiceInVat.vue';

describe('InvoiceInVat', () => {
    let vm;

    beforeAll(() => {
        vm = createWrapper(InvoiceInVat, {
            global: {
                stubs: [],
                mocks: {
                    fetch: vi.fn(),
                },
            },
        }).vm;
    });

    describe('taxRate()', () => {
        it('should correctly compute the tax rate', () => {
            const invoiceInTax = { taxableBase: 100, taxTypeSageFk: 1 };
            vm.sageTaxTypes = [
                { id: 1, rate: 10 },
                { id: 2, rate: 20 },
            ];
            const result = vm.taxRate(invoiceInTax);
            expect(result).toBe((10 / 100) * 100);
        });

        it('should return 0 if there is not tax rate', () => {
            const invoiceInTax = { taxableBase: 100, taxTypeSageFk: 1 };
            vm.sageTaxTypes = [];

            const result = vm.taxRate(invoiceInTax);
            expect(result).toBe(0);
        });
    });
});
