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.

71 lines
2.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import { beforeEach, describe, expect, it, vi } from "vitest";
import type { FlockRunQuoteResult } from "@/workers/rpa/flock/types";
const visualChainMock = vi.fn<() => Promise<FlockRunQuoteResult>>();
vi.mock("@/workers/rpa/flock/visual-chain", () => ({
runFlockVisualChain: () => visualChainMock(),
}));
describe("runFlockVisualChainWithRotations", () => {
beforeEach(() => {
visualChainMock.mockReset();
process.env.FLOCK_SESSION_MAX_ROTATIONS = "3";
});
it("拒号时换邮箱重试直至成功", async () => {
visualChainMock
.mockResolvedValueOnce({
ok: false,
quotes: [],
errorMessage: "FLOCK_ACCOUNT_REJECTEDissue creating your account",
})
.mockResolvedValueOnce({
ok: true,
quotes: [{ tier: "standard", totalUsd: 100 } as FlockRunQuoteResult["quotes"][0]],
});
const { runFlockVisualChainWithRotations } = await import(
"@/workers/rpa/flock/run-quote"
);
const result = await runFlockVisualChainWithRotations({
pickupZip: "94102",
deliveryZip: "90212",
pickupDate: "2026-07-20",
palletCount: 4,
totalWeightLb: 2800,
lengthIn: 48,
widthIn: 40,
heightIn: 48,
});
expect(result.ok).toBe(true);
expect(visualChainMock).toHaveBeenCalledTimes(2);
});
it("报价上限时不轮换", async () => {
visualChainMock.mockResolvedValue({
ok: false,
quotes: [],
errorMessage: "FLOCK_QUOTE_LIMITThank you for your interest",
});
const { runFlockVisualChainWithRotations } = await import(
"@/workers/rpa/flock/run-quote"
);
const result = await runFlockVisualChainWithRotations({
pickupZip: "94102",
deliveryZip: "90212",
pickupDate: "2026-07-20",
palletCount: 4,
totalWeightLb: 2800,
lengthIn: 48,
widthIn: 40,
heightIn: 48,
});
expect(result.ok).toBe(false);
expect(visualChainMock).toHaveBeenCalledTimes(1);
});
});