You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.3 KiB
81 lines
2.3 KiB
import { describe, expect, it } from "vitest";
|
|
import {
|
|
resolveConfirmInstruction,
|
|
} from "@/services/parse/resolve-confirm-instruction";
|
|
import type { MailInstructionUnit } from "@/services/parse/split-instructions";
|
|
|
|
function unit(
|
|
partial: Partial<MailInstructionUnit> &
|
|
Pick<MailInstructionUnit, "id" | "uiKind">,
|
|
): MailInstructionUnit {
|
|
return {
|
|
mailType: "NEW_CONTAINER",
|
|
label: partial.uiKind,
|
|
summary: "",
|
|
keywords: [],
|
|
source: "body_segment",
|
|
segmentIndex: 0,
|
|
isCurrent: false,
|
|
segmentText: "",
|
|
...partial,
|
|
};
|
|
}
|
|
|
|
describe("resolveConfirmInstruction", () => {
|
|
const forecast = unit({
|
|
id: "forecast-body_segment-5-派送单请查收",
|
|
uiKind: "forecast",
|
|
isCurrent: false,
|
|
});
|
|
const transfer = unit({
|
|
id: "transfer-body_segment-0-新增转仓",
|
|
uiKind: "transfer",
|
|
mailType: "TRANSFER",
|
|
isCurrent: true,
|
|
});
|
|
|
|
it("selects the requested instruction even when it is historical forecast", () => {
|
|
const resolved = resolveConfirmInstruction({
|
|
units: [transfer, forecast],
|
|
instructionId: forecast.id,
|
|
});
|
|
expect(resolved.reason).toBe("ok");
|
|
expect(resolved.unit?.id).toBe(forecast.id);
|
|
expect(resolved.unit?.uiKind).toBe("forecast");
|
|
});
|
|
|
|
it("does not infer from mail main type when instruction_id is missing and multiple units exist", () => {
|
|
const resolved = resolveConfirmInstruction({
|
|
units: [transfer, forecast],
|
|
});
|
|
expect(resolved.reason).toBe("missing_id");
|
|
expect(resolved.unit).toBeNull();
|
|
expect(resolved.candidates.map((u) => u.uiKind)).toEqual([
|
|
"transfer",
|
|
"forecast",
|
|
]);
|
|
});
|
|
|
|
it("auto-selects the only pending confirmable unit", () => {
|
|
const resolved = resolveConfirmInstruction({
|
|
units: [forecast],
|
|
});
|
|
expect(resolved.reason).toBe("ok");
|
|
expect(resolved.unit?.id).toBe(forecast.id);
|
|
});
|
|
|
|
it("keeps an already-imported unit visible as readonly", () => {
|
|
const resolved = resolveConfirmInstruction({
|
|
units: [forecast],
|
|
instructionId: forecast.id,
|
|
lineage: {
|
|
instruction_state: {
|
|
[forecast.id]: { status: "IMPORTED", importedAt: "2026-08-17" },
|
|
},
|
|
},
|
|
});
|
|
expect(resolved.reason).toBe("already_imported");
|
|
expect(resolved.unit?.id).toBe(forecast.id);
|
|
});
|
|
});
|