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.

29 lines
966 B

import { describe, expect, it } from "vitest";
import { computeRawHash, computeShipmentsHash, md5 } from "@/utils/hash";
import { toShanghaiDateString, round4 } from "@/utils/dates";
describe("hash/dates", () => {
it("md5 lowercase hex", () => {
expect(md5("abc")).toBe("900150983cd24fb0d6963f7d28e17f72");
});
it("shipments hash stable", () => {
expect(computeShipmentsHash("MATU2745683", [2, 1])).toBe(
computeShipmentsHash("MATU2745683", [1, 2]),
);
});
it("raw hash differs", () => {
expect(
computeRawHash({ subject: "a", from: "b", date: "c", filenames: [] }),
).not.toBe(
computeRawHash({ subject: "x", from: "b", date: "c", filenames: [] }),
);
});
it("shanghai date boundary", () => {
const d = new Date("2026-07-12T16:30:00.000Z"); // UTC+8 next day morning
expect(toShanghaiDateString(d)).toBe("2026-07-13");
});
it("round4", () => {
expect(round4(0.12345)).toBe(0.1235);
});
});