2026-07-17 10:45:59 -03:00
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
|
import { formatBoardAuditAction } from "@/domain/work-orders/utils/format-board-audit-action";
|
|
|
|
|
|
|
|
|
|
describe("formatBoardAuditAction", () => {
|
|
|
|
|
it("keeps human sentences from action as-is", () => {
|
|
|
|
|
expect(
|
|
|
|
|
formatBoardAuditAction({
|
|
|
|
|
action: 'Changed status to "Incomplete"',
|
|
|
|
|
fieldName: "",
|
|
|
|
|
oldValue: "",
|
|
|
|
|
newValue: "",
|
|
|
|
|
}),
|
|
|
|
|
).toBe('Changed status to "Incomplete"');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("formats lifecycle status from field/newValue", () => {
|
|
|
|
|
expect(
|
|
|
|
|
formatBoardAuditAction({
|
|
|
|
|
action: "StatusChanged",
|
|
|
|
|
fieldName: "LifecycleStatus",
|
|
|
|
|
oldValue: "Scheduled",
|
|
|
|
|
newValue: "Incomplete",
|
|
|
|
|
}),
|
|
|
|
|
).toBe('Changed status to "Incomplete"');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("formats WeekRolled / CarriedOver with increment", () => {
|
|
|
|
|
expect(
|
|
|
|
|
formatBoardAuditAction({
|
|
|
|
|
action: "WeekRolled",
|
|
|
|
|
fieldName: "CarriedOver",
|
|
|
|
|
oldValue: "0",
|
|
|
|
|
newValue: "1",
|
|
|
|
|
}),
|
|
|
|
|
).toBe("Carried over to the next week (increment #1)");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("formats schedule changes", () => {
|
|
|
|
|
expect(
|
|
|
|
|
formatBoardAuditAction({
|
|
|
|
|
action: "Rescheduled",
|
|
|
|
|
fieldName: "ScheduledDate",
|
|
|
|
|
oldValue: "2026-07-10",
|
|
|
|
|
newValue: "2026-07-16",
|
|
|
|
|
}),
|
|
|
|
|
).toBe('Changed schedule to "07/16/2026"');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("formats appt time ISO range as mm/dd/yyyy", () => {
|
|
|
|
|
expect(
|
|
|
|
|
formatBoardAuditAction({
|
|
|
|
|
action: "ApptTimeChanged",
|
|
|
|
|
fieldName: "ApptTime",
|
|
|
|
|
oldValue: "",
|
|
|
|
|
newValue: "2026-07-13T05:30:00.0000000|2026-07-13T07:00:00.0000000",
|
|
|
|
|
}),
|
|
|
|
|
).toBe('Changed appt time to "07/13/2026"');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("formats past due system message", () => {
|
|
|
|
|
expect(
|
|
|
|
|
formatBoardAuditAction({
|
|
|
|
|
action: "MarkedPastDue",
|
|
|
|
|
fieldName: "IsPastDue",
|
|
|
|
|
oldValue: "false",
|
|
|
|
|
newValue: "true",
|
|
|
|
|
}),
|
2026-08-11 13:49:41 -03:00
|
|
|
).toBe("WO marked as Past Due. Due date has passed without completion.");
|
2026-07-17 10:45:59 -03:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("falls back to from → to for unknown fields", () => {
|
|
|
|
|
expect(
|
|
|
|
|
formatBoardAuditAction({
|
|
|
|
|
action: "FieldPatched",
|
|
|
|
|
fieldName: "VendorNte",
|
|
|
|
|
oldValue: "100",
|
|
|
|
|
newValue: "250",
|
|
|
|
|
}),
|
|
|
|
|
).toBe('Changed vendor nte from "100" to "250"');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("formats JSON array values as comma-separated quoted items", () => {
|
|
|
|
|
expect(
|
|
|
|
|
formatBoardAuditAction({
|
|
|
|
|
action: "FieldPatched",
|
|
|
|
|
fieldName: "ExtraServices",
|
|
|
|
|
oldValue: "",
|
|
|
|
|
newValue: '["Other","Installation","Preventive Maintenance"]',
|
|
|
|
|
}),
|
|
|
|
|
).toBe('Changed extra services to "Other", "Installation", "Preventive Maintenance"');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("falls back to Updated work order when empty", () => {
|
|
|
|
|
expect(
|
|
|
|
|
formatBoardAuditAction({
|
|
|
|
|
action: "",
|
|
|
|
|
fieldName: "Something",
|
|
|
|
|
oldValue: "",
|
|
|
|
|
newValue: "",
|
|
|
|
|
}),
|
|
|
|
|
).toBe("Updated work order");
|
|
|
|
|
});
|
|
|
|
|
});
|