salix-front/test/vitest/__tests__/pages/InvoiceIn/InvoiceInVat.spec.js

76 lines
2.3 KiB
JavaScript
Raw Normal View History

2023-11-09 09:29:28 +00:00
import { vi, describe, expect, it, beforeAll } from 'vitest';
import { createWrapper, axios } 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('addExpense()', () => {
beforeAll(() => {
vi.spyOn(axios, 'post').mockResolvedValue({ data: [] });
vi.spyOn(axios, 'get').mockResolvedValue({ data: [] });
vi.spyOn(vm.quasar, 'notify');
});
it('should throw an error when the code property is undefined', async () => {
await vm.addExpense();
expect(vm.quasar.notify).toHaveBeenCalledWith(
expect.objectContaining({
message: `The code can't be empty`,
type: 'negative',
})
);
});
it('should correctly handle expense addition', async () => {
vm.newExpense = {
code: 123,
isWithheld: false,
description: 'Descripción del gasto',
};
await vm.addExpense();
expect(vm.quasar.notify).toHaveBeenCalledWith(
expect.objectContaining({
message: 'Data saved',
type: 'positive',
})
);
});
});
describe('taxRate()', () => {
it('should correctly compute the tax rate', () => {
const invoiceInTax = { taxableBase: 100 };
const sageTaxTypeId = 1;
vm.sageTaxTypes = [
{ id: 1, rate: 10 },
{ id: 2, rate: 20 },
];
const result = vm.taxRate(invoiceInTax, sageTaxTypeId);
expect(result).toBe((10 / 100) * 100);
});
it('should return 0 if there is not tax rate', () => {
const invoiceInTax = { taxableBase: 100 };
const sageTaxTypeId = 1;
vm.sageTaxTypes = [];
const result = vm.taxRate(invoiceInTax, sageTaxTypeId);
expect(result).toBe(0);
});
});
});