2023-04-11 12:36:12 +00:00
|
|
|
import { vi, describe, expect, it, beforeAll, beforeEach, afterEach } from 'vitest';
|
|
|
|
import { createWrapper, axios } from 'app/test/vitest/helper';
|
|
|
|
import ClaimLines from 'pages/Claim/Card/ClaimLines.vue';
|
|
|
|
|
|
|
|
describe('ClaimLines', () => {
|
|
|
|
let vm;
|
|
|
|
|
|
|
|
beforeAll(() => {
|
|
|
|
vm = createWrapper(ClaimLines, {
|
|
|
|
global: {
|
|
|
|
stubs: ['FetchData', 'VnPaginate'],
|
|
|
|
mocks: {
|
|
|
|
fetch: vi.fn(),
|
|
|
|
},
|
2023-08-17 13:32:56 +00:00
|
|
|
},
|
2023-04-11 12:36:12 +00:00
|
|
|
}).vm;
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
vm.claim = {
|
|
|
|
id: 1,
|
2023-08-17 13:32:56 +00:00
|
|
|
ticketFk: 1,
|
|
|
|
};
|
2023-04-11 12:36:12 +00:00
|
|
|
vm.store.data = [
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
quantity: 10,
|
|
|
|
sale: {
|
2023-08-17 13:32:56 +00:00
|
|
|
id: 1,
|
|
|
|
discount: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
});
|
2023-04-11 12:36:12 +00:00
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vi.clearAllMocks();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('updateDiscount()', () => {
|
|
|
|
it('should make a POST request to endpoint "updateDiscount"', async () => {
|
|
|
|
vi.spyOn(axios, 'post').mockResolvedValue({ data: true });
|
|
|
|
vi.spyOn(vm.quasar, 'notify');
|
|
|
|
|
2023-08-17 13:32:56 +00:00
|
|
|
const canceller = new AbortController();
|
2023-04-11 12:36:12 +00:00
|
|
|
await vm.updateDiscount({ saleFk: 1, discount: 5, canceller });
|
|
|
|
|
2023-08-17 13:32:56 +00:00
|
|
|
const expectedData = { salesIds: [1], newDiscount: 5 };
|
|
|
|
expect(axios.post).toHaveBeenCalledWith(
|
|
|
|
'Tickets/1/updateDiscount',
|
|
|
|
expectedData,
|
|
|
|
{
|
|
|
|
signal: canceller.signal,
|
|
|
|
}
|
|
|
|
);
|
2023-04-11 12:36:12 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onUpdateDiscount()', () => {
|
|
|
|
it('should make a POST request and then set the discount on the original row', async () => {
|
|
|
|
vi.spyOn(vm.quasar, 'notify');
|
|
|
|
|
|
|
|
vm.onUpdateDiscount({ discount: 5, rowIndex: 0 });
|
2023-08-17 13:32:56 +00:00
|
|
|
const firstRow = vm.store.data[0];
|
2023-04-11 12:36:12 +00:00
|
|
|
|
2023-08-17 13:32:56 +00:00
|
|
|
expect(firstRow.sale.discount).toEqual(5);
|
2023-04-11 12:36:12 +00:00
|
|
|
expect(vm.quasar.notify).toHaveBeenCalledWith(
|
|
|
|
expect.objectContaining({
|
|
|
|
message: 'Discount updated',
|
2023-08-17 13:32:56 +00:00
|
|
|
type: 'positive',
|
2023-04-11 12:36:12 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|