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.
101 lines
2.9 KiB
101 lines
2.9 KiB
import { describe, expect, it, vi, beforeEach } from "vitest";
|
|
|
|
vi.mock("@/lib/prisma", () => ({
|
|
prisma: {
|
|
quoteRecord: {
|
|
findUnique: vi.fn(),
|
|
},
|
|
},
|
|
}));
|
|
|
|
vi.mock("@/lib/flock/flock-pricing-options-store", () => ({
|
|
saveFlockPricingOptions: vi.fn(),
|
|
readFlockPricingOptions: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("@/modules/flock/pricing-options-queue", () => ({
|
|
enqueueFlockPricingOptionsJob: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("@/lib/flock/flock-quote-hold-store", () => ({
|
|
readFlockQuoteHoldByQuoteId: vi.fn(),
|
|
}));
|
|
|
|
import { prisma } from "@/lib/prisma";
|
|
import {
|
|
saveFlockPricingOptions,
|
|
readFlockPricingOptions,
|
|
} from "@/lib/flock/flock-pricing-options-store";
|
|
import { readFlockQuoteHoldByQuoteId } from "@/lib/flock/flock-quote-hold-store";
|
|
import { enqueueFlockPricingOptionsJob } from "@/modules/flock/pricing-options-queue";
|
|
import { submitFlockPricingOptions } from "@/modules/flock/pricing-options-service";
|
|
|
|
describe("submitFlockPricingOptions", () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
vi.mocked(readFlockQuoteHoldByQuoteId).mockResolvedValue(null);
|
|
vi.mocked(readFlockPricingOptions).mockResolvedValue(null);
|
|
vi.mocked(enqueueFlockPricingOptionsJob).mockResolvedValue(undefined as never);
|
|
vi.mocked(prisma.quoteRecord.findUnique).mockResolvedValue({
|
|
quoteId: "q1",
|
|
customerId: "c1",
|
|
requestId: "r1",
|
|
status: "done",
|
|
pickupJson: { zip: "90001", flock_pickup_date: "2026-07-30" },
|
|
deliveryJson: { zip: "10001" },
|
|
weightLb: 500,
|
|
dimLIn: 48,
|
|
dimWIn: 40,
|
|
dimHIn: 48,
|
|
palletCount: 2,
|
|
quotesJson: {
|
|
provider: "flock",
|
|
reference: "JKR-RH3X",
|
|
lines: [],
|
|
},
|
|
} as never);
|
|
});
|
|
|
|
it("仅选档位即可入队(不要求已选灵活档)", async () => {
|
|
const r = await submitFlockPricingOptions({
|
|
customerId: "c1",
|
|
quoteId: "q1",
|
|
preferredTier: "standard",
|
|
});
|
|
expect(r.status).toBe("processing");
|
|
expect(enqueueFlockPricingOptionsJob).toHaveBeenCalled();
|
|
expect(saveFlockPricingOptions).toHaveBeenCalled();
|
|
});
|
|
|
|
it("非法档位拒绝", async () => {
|
|
await expect(
|
|
submitFlockPricingOptions({
|
|
customerId: "c1",
|
|
quoteId: "q1",
|
|
preferredTier: "nope" as never,
|
|
}),
|
|
).rejects.toThrow(/FlockDirect|Standard/);
|
|
});
|
|
|
|
it("有效 hold 时入队携带 quoteSessionId", async () => {
|
|
const now = Date.now();
|
|
vi.mocked(readFlockQuoteHoldByQuoteId).mockResolvedValue({
|
|
quote_id: "q1",
|
|
customer_id: "c1",
|
|
quote_session_id: "flock_QTE_hold",
|
|
status: "awaiting_decision",
|
|
parked_at_ms: now,
|
|
decision_deadline_ms: now + 60_000,
|
|
total_deadline_ms: now + 300_000,
|
|
});
|
|
await submitFlockPricingOptions({
|
|
customerId: "c1",
|
|
quoteId: "q1",
|
|
preferredTier: "flock_direct",
|
|
});
|
|
expect(enqueueFlockPricingOptionsJob).toHaveBeenCalledWith(
|
|
expect.objectContaining({ quoteSessionId: "flock_QTE_hold" }),
|
|
);
|
|
});
|
|
});
|