Ночное задание spam-rescue: возврат инвойсов из Спама (слова проектов/клиентов/вендоров, белый список, фильтры Gmail), миграция 075
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
29
packages/accounting_automation/src/spam-rescue.test.ts
Normal file
29
packages/accounting_automation/src/spam-rescue.test.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { decide, normalizeTerm, projectNumberOf, senderEmail, type RescueRules } from "./spam-rescue.js";
|
||||
|
||||
const rules: RescueRules = { whitelist: new Set(["billing@ok.com"]), terms: ["dumpster dudez", "united rentals"], projectNumbers: ["734", "256"] };
|
||||
const mail = (o: Partial<{ from: string; subject: string; snippet: string; recipients: string }>) => ({ id: "1", from: "x <x@y.com>", subject: "", snippet: "", recipients: "invoice@khbuild.pro", ...o });
|
||||
|
||||
describe("spam-rescue decide", () => {
|
||||
it("слово вендора + invoice@ -> вернуть", () => {
|
||||
expect(decide(mail({ subject: "You have a new invoice #2814", from: "'Dumpster Dudez of Greater Tampa' via Invoice <i@khbuild.pro>" }), rules).rescue).toBe(true);
|
||||
});
|
||||
it("номер проекта", () => {
|
||||
expect(decide(mail({ subject: "Invoice for 734 Placido" }), rules).rescue).toBe(true);
|
||||
expect(decide(mail({ subject: "Order 17345" }), rules).rescue).toBe(false);
|
||||
});
|
||||
it("не на invoice@ - не трогаем, если нет белого списка", () => {
|
||||
expect(decide(mail({ subject: "734", recipients: "nastia@khbuild.pro" }), rules).rescue).toBe(false);
|
||||
expect(decide(mail({ from: "a <billing@ok.com>", recipients: "nastia@khbuild.pro" }), rules).rescue).toBe(true);
|
||||
});
|
||||
it("без слов - остаётся в спаме", () => {
|
||||
expect(decide(mail({ subject: "Win a prize" }), rules).rescue).toBe(false);
|
||||
});
|
||||
it("помощники", () => {
|
||||
expect(senderEmail('"A" <A@B.com>')).toBe("a@b.com");
|
||||
expect(normalizeTerm("Dumpster Dudez LLC")).toBe("dumpster dudez");
|
||||
expect(normalizeTerm("AB Inc")).toBeNull();
|
||||
expect(projectNumberOf("734 Placido Way NE")).toBe("734");
|
||||
expect(projectNumberOf("44.01")).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user