- Introduced e2e test for "Change Invoice Collection" in `change-invoice-collection.spec.ts`. - Added unit tests for `CollectedOrderInvoiceOverview.vue` including edit flow for `closed_at`. - Implemented tests for queue reliability, state handling, and customer actions: - `CollectedOrderInvoicesQueueHistory.vue`: polling, error handling, richer diagnostics, and retry logic. - `InvoicingBillingPeriod` views: refresh and queue state handling. - Enhanced test coverage for Stripe queue functionality and related actions.
98 lines
3.1 KiB
JavaScript
98 lines
3.1 KiB
JavaScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const getCustomerIdMock = vi.hoisted(() => vi.fn());
|
|
const setInvoiceCollectionIdMock = vi.hoisted(() => vi.fn());
|
|
const showInvoiceCollectionPickerFormMock = vi.hoisted(() => vi.fn());
|
|
|
|
vi.mock("sweetalert2", () => ({
|
|
default: {
|
|
fire: vi.fn(() => Promise.resolve()),
|
|
close: vi.fn(),
|
|
},
|
|
}));
|
|
|
|
vi.mock("@/i18n", () => ({
|
|
default: {
|
|
global: {
|
|
t: (key) => key,
|
|
},
|
|
},
|
|
}));
|
|
|
|
vi.mock("@/components/session/token/SessionUser.vue", () => ({
|
|
SessionUser: {
|
|
objects: {
|
|
orders: {
|
|
functions: {
|
|
get_customer_id: getCustomerIdMock,
|
|
},
|
|
set: {
|
|
invoice_collection_id: setInvoiceCollectionIdMock,
|
|
},
|
|
},
|
|
collectedOrderInvoices: {
|
|
functions: {
|
|
showInvoiceCollectionPickerForm: showInvoiceCollectionPickerFormMock,
|
|
},
|
|
},
|
|
},
|
|
request: vi.fn(() => Promise.resolve({ data: { data: {} } })),
|
|
functions: {
|
|
parseErrorMessage: vi.fn(() => "error"),
|
|
},
|
|
},
|
|
}));
|
|
|
|
import Swal from "sweetalert2";
|
|
import { Orders } from "@/components/session/token/SessionUser/Objects/Orders.vue";
|
|
|
|
describe("Orders.showChangeInvoiceCollectionForm", () => {
|
|
beforeEach(() => {
|
|
getCustomerIdMock.mockReset();
|
|
setInvoiceCollectionIdMock.mockReset();
|
|
showInvoiceCollectionPickerFormMock.mockReset();
|
|
Swal.fire.mockClear();
|
|
});
|
|
|
|
it("updates invoice collection and calls onAfterSubmit without page reload timing", async () => {
|
|
const setTimeoutSpy = vi.spyOn(globalThis, "setTimeout");
|
|
const onAfterSubmit = vi.fn(() => Promise.resolve());
|
|
|
|
getCustomerIdMock.mockResolvedValue(123456);
|
|
setInvoiceCollectionIdMock.mockResolvedValue({ data: { success: true } });
|
|
showInvoiceCollectionPickerFormMock.mockImplementation(async (_customerNumber, onSelected) => {
|
|
await onSelected(9001);
|
|
});
|
|
|
|
await Orders.functions.showChangeInvoiceCollectionForm(45, onAfterSubmit);
|
|
|
|
expect(getCustomerIdMock).toHaveBeenCalledWith(45);
|
|
expect(showInvoiceCollectionPickerFormMock).toHaveBeenCalledWith(123456, expect.any(Function));
|
|
expect(setInvoiceCollectionIdMock).toHaveBeenCalledWith(45, 9001);
|
|
expect(onAfterSubmit).toHaveBeenCalledTimes(1);
|
|
expect(Swal.fire).toHaveBeenCalledWith(expect.objectContaining({ icon: "success" }));
|
|
expect(setTimeoutSpy).not.toHaveBeenCalled();
|
|
|
|
setTimeoutSpy.mockRestore();
|
|
});
|
|
|
|
it("does not update invoice collection when no selection is made", async () => {
|
|
const setTimeoutSpy = vi.spyOn(globalThis, "setTimeout");
|
|
const onAfterSubmit = vi.fn(() => Promise.resolve());
|
|
|
|
getCustomerIdMock.mockResolvedValue(98765);
|
|
showInvoiceCollectionPickerFormMock.mockImplementation(async (_customerNumber, onSelected) => {
|
|
await onSelected(null);
|
|
});
|
|
|
|
await Orders.functions.showChangeInvoiceCollectionForm(88, onAfterSubmit);
|
|
|
|
expect(setInvoiceCollectionIdMock).not.toHaveBeenCalled();
|
|
expect(onAfterSubmit).not.toHaveBeenCalled();
|
|
expect(Swal.fire).toHaveBeenCalledWith(expect.objectContaining({ icon: "error" }));
|
|
expect(setTimeoutSpy).not.toHaveBeenCalled();
|
|
|
|
setTimeoutSpy.mockRestore();
|
|
});
|
|
});
|