91 lines
2.4 KiB
JavaScript
91 lines
2.4 KiB
JavaScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
filterUsageOrdersByAttachment,
|
|
isUsageOrderAttachedToOrder,
|
|
} from "@/components/displays/department/pos/sync/xlvaskUsageFilters.js";
|
|
|
|
describe("xlvask usage filters", () => {
|
|
it("detects when a generated usage row is attached to an existing order", () => {
|
|
const attachedObject = {
|
|
wash_id: 101,
|
|
duplicates: [
|
|
{ id: 1, wash_id: 45 },
|
|
{ id: 2, wash_id: 101 },
|
|
],
|
|
};
|
|
|
|
const unattachedObject = {
|
|
wash_id: 202,
|
|
duplicates: [{ id: 3, wash_id: 45 }],
|
|
};
|
|
|
|
expect(isUsageOrderAttachedToOrder(attachedObject)).toBe(true);
|
|
expect(isUsageOrderAttachedToOrder(unattachedObject)).toBe(false);
|
|
});
|
|
|
|
it("keeps all rows when the unattached-only switch is disabled", () => {
|
|
const sourceRows = [
|
|
{ id: 1, wash_id: 10, duplicates: [{ wash_id: 10 }] },
|
|
{ id: 2, wash_id: 20, duplicates: [{ wash_id: 99 }] },
|
|
{ id: 3, wash_id: 30 },
|
|
];
|
|
|
|
expect(filterUsageOrdersByAttachment(sourceRows, false)).toEqual(sourceRows);
|
|
});
|
|
|
|
it("treats accepted automation actions as attached", () => {
|
|
expect(
|
|
isUsageOrderAttachedToOrder({
|
|
wash_id: "wash-1",
|
|
duplicates: [],
|
|
automation: {
|
|
status: "accepted",
|
|
action: "attach_order",
|
|
},
|
|
})
|
|
).toBe(true);
|
|
|
|
expect(
|
|
isUsageOrderAttachedToOrder({
|
|
wash_id: "wash-2",
|
|
duplicates: [],
|
|
automation: {
|
|
status: "denied",
|
|
action: "attach_order",
|
|
},
|
|
})
|
|
).toBe(false);
|
|
});
|
|
|
|
it("treats direct linked order metadata as attached", () => {
|
|
expect(
|
|
isUsageOrderAttachedToOrder({
|
|
wash_id: "wash-1",
|
|
linked_order_id: 61355,
|
|
duplicates: [],
|
|
})
|
|
).toBe(true);
|
|
|
|
expect(
|
|
isUsageOrderAttachedToOrder({
|
|
wash_id: "wash-2",
|
|
linked_order_id: null,
|
|
duplicates: [],
|
|
})
|
|
).toBe(false);
|
|
});
|
|
|
|
it("returns only rows not attached to existing orders when enabled", () => {
|
|
const sourceRows = [
|
|
{ id: 1, wash_id: 10, duplicates: [{ wash_id: 10 }] },
|
|
{ id: 2, wash_id: 20, duplicates: [{ wash_id: 99 }] },
|
|
{ id: 3, wash_id: 30, duplicates: [] },
|
|
];
|
|
|
|
expect(filterUsageOrdersByAttachment(sourceRows, true)).toEqual([
|
|
{ id: 2, wash_id: 20, duplicates: [{ wash_id: 99 }] },
|
|
{ id: 3, wash_id: 30, duplicates: [] },
|
|
]);
|
|
});
|
|
});
|