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.
50 lines
1.3 KiB
50 lines
1.3 KiB
import { describe, expect, it } from "vitest";
|
|
import {
|
|
normalizeQuote,
|
|
resolveRatesFromBody,
|
|
} from "@/workers/rpa/quote-capture/quote-normalize";
|
|
import { satisfiesQuoteContract } from "@/workers/rpa/quote-capture/quote-contract-guard";
|
|
|
|
const rates = {
|
|
standard: {
|
|
lowest: { price: 100, transitDays: "5d" },
|
|
fastest: { price: 120, transitDays: "3d" },
|
|
},
|
|
guaranteed: {
|
|
lowest: { price: 200, transitDays: "5d" },
|
|
fastest: { price: 220, transitDays: "2d" },
|
|
},
|
|
};
|
|
|
|
describe("resolveRatesFromBody", () => {
|
|
it("body.rates", () => {
|
|
expect(resolveRatesFromBody({ rates })?.sourcePath).toBe("rates");
|
|
});
|
|
|
|
it("body.data.rates", () => {
|
|
expect(resolveRatesFromBody({ data: { rates } })?.sourcePath).toBe(
|
|
"data.rates",
|
|
);
|
|
});
|
|
|
|
it("body.result.rates", () => {
|
|
expect(resolveRatesFromBody({ result: { rates } })?.sourcePath).toBe(
|
|
"result.rates",
|
|
);
|
|
});
|
|
|
|
it("array[0].rates", () => {
|
|
expect(resolveRatesFromBody([{ rates }])?.sourcePath).toBe("[0].rates");
|
|
});
|
|
});
|
|
|
|
describe("normalizeQuote + contract", () => {
|
|
it("data.rates 通过契约", () => {
|
|
expect(satisfiesQuoteContract({ data: { rates } })).toBe(true);
|
|
});
|
|
|
|
it("无 rates 返回 null", () => {
|
|
expect(normalizeQuote({ foo: 1 })).toBeNull();
|
|
});
|
|
});
|