Files
streamline/control-server/test/batch_import_log.test.ts
T
2026-11-16 17:26:44 -08:00

46 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, test } from "bun:test";
import { canRetry, countImportGroups, evidenceOf, importGroupOf, outcomeOfSkip } from "@bbbug/shared/batch_import_log";
describe("importGroupOf", () => {
test("新建 / 补标签算已导入,忽略不改变这一点", () => {
expect(importGroupOf({ outcome: "created", ignoredAt: null })).toBe("imported");
expect(importGroupOf({ outcome: "retagged", ignoredAt: 1 })).toBe("imported");
});
test("没导进来的:没人忽略 = 待处理,忽略了 = 已忽略", () => {
for (const outcome of ["set_aside", "failed", "pending"] as const) {
expect(importGroupOf({ outcome, ignoredAt: null })).toBe("todo");
expect(importGroupOf({ outcome, ignoredAt: 1 })).toBe("ignored");
}
});
});
test("countImportGroups:失败只数没被忽略的", () => {
const c = countImportGroups([
{ outcome: "created", ignoredAt: null }, { outcome: "failed", ignoredAt: null },
{ outcome: "failed", ignoredAt: 5 }, { outcome: "set_aside", ignoredAt: null },
]);
expect(c).toEqual({ todo: 2, imported: 1, ignored: 1, failed: 1 });
});
test("canRetry:导进来的不能再导", () => {
expect(canRetry({ outcome: "created" })).toBe(false);
expect(canRetry({ outcome: "retagged" })).toBe(false);
expect(canRetry({ outcome: "set_aside" })).toBe(true);
expect(canRetry({ outcome: "failed" })).toBe(true);
expect(canRetry({ outcome: "pending" })).toBe(true);
});
test("outcomeOfSkip:duplicate = 别人先导进来了,其余算失败并保留原文", () => {
expect(outcomeOfSkip("duplicate")).toEqual({ outcome: "retagged", reason: null });
expect(outcomeOfSkip("unparseable").outcome).toBe("failed");
expect(outcomeOfSkip("Product profile is unavailable")).toEqual({ outcome: "failed", reason: "Product profile is unavailable" });
});
test("evidenceOf:只带有值的字段", () => {
const e = evidenceOf({
meegoId: "1", url: "u", checked: true, title: "t", meegoState: "OPEN", meegoOpen: true,
mrs: [{ mrId: 1, title: "", author: null, state: "closed", url: "" }], existing: null, bucket: "mr", warnings: [],
});
expect(e).toEqual({ meegoState: "OPEN", mrs: [{ mrId: 1, title: "", author: null, state: "closed", url: "" }] });
});