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.
54 lines
1.5 KiB
54 lines
1.5 KiB
import { describe, expect, it } from "vitest";
|
|
import { shouldReuseCcMemoryToken } from "@/services/cc/auth";
|
|
import { summarizeBody, deriveMailContentKind } from "@/utils/mailContent";
|
|
|
|
describe("CC token memory reuse", () => {
|
|
const loginMark = "mark-1";
|
|
|
|
it("reuses memory token when plenty of TTL remains", () => {
|
|
const expireAt = new Date(Date.now() + 2 * 60 * 60 * 1000);
|
|
expect(
|
|
shouldReuseCcMemoryToken(
|
|
{ loginMark, expireAt },
|
|
loginMark,
|
|
Date.now(),
|
|
),
|
|
).toBe(true);
|
|
});
|
|
|
|
it("does not reuse when loginMark differs", () => {
|
|
expect(
|
|
shouldReuseCcMemoryToken(
|
|
{ loginMark: "other", expireAt: new Date(Date.now() + 3_600_000) },
|
|
loginMark,
|
|
Date.now(),
|
|
),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("falls back to DB when remaining TTL is under 30s", () => {
|
|
expect(
|
|
shouldReuseCcMemoryToken(
|
|
{ loginMark, expireAt: new Date(Date.now() + 10_000) },
|
|
loginMark,
|
|
Date.now(),
|
|
),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("does not reuse null memory", () => {
|
|
expect(shouldReuseCcMemoryToken(null, loginMark, Date.now())).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("mail list avoids loading body", () => {
|
|
it("summarizes from subject when body is omitted", () => {
|
|
expect(summarizeBody("柜预报 WHLU123")).toBe("柜预报 WHLU123");
|
|
});
|
|
|
|
it("classifies list rows from filenames without body", () => {
|
|
expect(deriveMailContentKind(["packing.xlsx"], ".")).toBe("PACKING_LIST");
|
|
expect(deriveMailContentKind([], ".")).toBe("PLAIN_TEXT");
|
|
});
|
|
});
|