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.
62 lines
1.7 KiB
62 lines
1.7 KiB
import { describe, expect, it, vi } from "vitest";
|
|
import {
|
|
parseFlockHoldFlexibilityJson,
|
|
parseFlockQuoteHoldJson,
|
|
} from "@/lib/flock/flock-quote-hold-store";
|
|
|
|
describe("parseFlockQuoteHoldJson", () => {
|
|
it("合法 JSON 通过", () => {
|
|
const raw = JSON.stringify({
|
|
quote_id: "q1",
|
|
quote_session_id: "flock_q1",
|
|
customer_id: "c1",
|
|
parked_at_ms: 1,
|
|
decision_deadline_ms: 2,
|
|
total_deadline_ms: 3,
|
|
status: "awaiting_decision",
|
|
});
|
|
expect(parseFlockQuoteHoldJson(raw)?.quote_id).toBe("q1");
|
|
});
|
|
|
|
it("缺字段 / 非法 status 返回 null", () => {
|
|
const spy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
expect(parseFlockQuoteHoldJson("{}")).toBeNull();
|
|
expect(
|
|
parseFlockQuoteHoldJson(
|
|
JSON.stringify({
|
|
quote_id: "q1",
|
|
quote_session_id: "flock_q1",
|
|
customer_id: "c1",
|
|
parked_at_ms: 1,
|
|
decision_deadline_ms: 2,
|
|
total_deadline_ms: 3,
|
|
status: "hacked",
|
|
}),
|
|
),
|
|
).toBeNull();
|
|
expect(parseFlockQuoteHoldJson("not-json")).toBeNull();
|
|
spy.mockRestore();
|
|
});
|
|
});
|
|
|
|
describe("parseFlockHoldFlexibilityJson", () => {
|
|
it("合法 flex 通过;非法 key 拒绝", () => {
|
|
const ok = JSON.stringify({
|
|
flock_direct: [
|
|
{ key: "2_day", label: "2天", rateUsd: 100 },
|
|
],
|
|
});
|
|
expect(parseFlockHoldFlexibilityJson(ok)?.flock_direct).toHaveLength(1);
|
|
|
|
const spy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
expect(
|
|
parseFlockHoldFlexibilityJson(
|
|
JSON.stringify({
|
|
flock_direct: [{ key: "bad", label: "x", rateUsd: 1 }],
|
|
}),
|
|
),
|
|
).toBeNull();
|
|
spy.mockRestore();
|
|
});
|
|
});
|