- Introduced `AssignDraftOrderCustomerModal` component with supporting localization for managing customer assignments. - Added e2e harness for modal testing in `assign-draft-order-customer-modal.html` and `assign-draft-order-customer-modal.ts`. - Implemented e2e test cases for customer assignment workflows in `assign-draft-order-modal-create.spec.ts` and `assign-draft-order-modal-layout.spec.ts`.
123 lines
3.3 KiB
JavaScript
123 lines
3.3 KiB
JavaScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const authenticatedRequestMock = vi.hoisted(() => vi.fn());
|
|
const getSystemUserIdsMock = vi.hoisted(() => vi.fn(() => []));
|
|
const isSystemUserIdMock = vi.hoisted(() => vi.fn((userId) => userId === 1857));
|
|
|
|
vi.mock("@/components/session/authenticatedRequest.vue", () => ({
|
|
authenticatedRequest: authenticatedRequestMock,
|
|
}));
|
|
|
|
vi.mock("@/components/session/token/SessionUser/Objects/systemUserIds.js", () => ({
|
|
getSystemUserIds: getSystemUserIdsMock,
|
|
isSystemUserId: isSystemUserIdMock,
|
|
default: getSystemUserIdsMock,
|
|
}));
|
|
|
|
import { fetchDepartmentDraftCount } from "@/components/models/navigation/items/adminDraftCount.js";
|
|
|
|
describe("fetchDepartmentDraftCount", () => {
|
|
const consoleErrorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
|
|
beforeEach(() => {
|
|
authenticatedRequestMock.mockReset();
|
|
consoleErrorSpy.mockClear();
|
|
getSystemUserIdsMock.mockReset();
|
|
getSystemUserIdsMock.mockReturnValue([]);
|
|
isSystemUserIdMock.mockReset();
|
|
isSystemUserIdMock.mockImplementation((userId) => Number(userId) === 1857);
|
|
});
|
|
|
|
it("returns pagination total when the orders request succeeds", async () => {
|
|
authenticatedRequestMock.mockResolvedValue({
|
|
data: {
|
|
data: [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }, { id: 6 }, { id: 7 }],
|
|
meta: {
|
|
pagination: {
|
|
total: 7,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
await expect(
|
|
fetchDepartmentDraftCount({
|
|
departmentId: 12,
|
|
customerNumber: 6001,
|
|
})
|
|
).resolves.toBe(7);
|
|
|
|
expect(authenticatedRequestMock).toHaveBeenCalledWith("/orders", "GET", {
|
|
filters: "department_id:12,customer_id:6001",
|
|
page: 1,
|
|
limit: 100,
|
|
search: "",
|
|
order: "id:DESC",
|
|
});
|
|
});
|
|
|
|
it("filters out system drafts that are hidden for non-superusers", async () => {
|
|
getSystemUserIdsMock.mockReturnValue([1857]);
|
|
authenticatedRequestMock.mockResolvedValue({
|
|
data: {
|
|
data: [
|
|
{ id: 1, cashier_id: 1857 },
|
|
{ id: 2, cashier_id: 12 },
|
|
{ id: 3, cashier_id: 24 },
|
|
],
|
|
meta: {
|
|
pagination: {
|
|
total: 3,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
await expect(
|
|
fetchDepartmentDraftCount({
|
|
departmentId: 12,
|
|
customerNumber: 6001,
|
|
})
|
|
).resolves.toBe(2);
|
|
|
|
expect(authenticatedRequestMock).toHaveBeenCalledWith("/orders", "GET", {
|
|
filters: "department_id:12,customer_id:6001",
|
|
page: 1,
|
|
limit: 100,
|
|
search: "",
|
|
order: "id:DESC",
|
|
});
|
|
});
|
|
|
|
it("returns 0 when the department or customer is invalid", async () => {
|
|
await expect(
|
|
fetchDepartmentDraftCount({
|
|
departmentId: null,
|
|
customerNumber: 6001,
|
|
})
|
|
).resolves.toBe(0);
|
|
|
|
await expect(
|
|
fetchDepartmentDraftCount({
|
|
departmentId: 12,
|
|
customerNumber: 0,
|
|
})
|
|
).resolves.toBe(0);
|
|
|
|
expect(authenticatedRequestMock).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("returns 0 when the orders request fails", async () => {
|
|
authenticatedRequestMock.mockRejectedValue(new Error("Request failed"));
|
|
|
|
await expect(
|
|
fetchDepartmentDraftCount({
|
|
departmentId: 12,
|
|
customerNumber: 6001,
|
|
})
|
|
).resolves.toBe(0);
|
|
|
|
expect(consoleErrorSpy).toHaveBeenCalled();
|
|
});
|
|
});
|