Initial import of streamline
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
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: "" }] });
|
||||
});
|
||||
Reference in New Issue
Block a user