feat(watcher): add Tokopedia order parsing and rules

Implement parsing for Tokopedia "Pesanan Selesai" messages, including support for single and multi-item orders. Update rules to recognize Tokopedia order completion and enhance spending record mapping. Add tests to validate new functionality.
This commit is contained in:
2026-09-13 23:58:23 +07:00
parent 0fa0ed3380
commit c446d794a8
9 changed files with 338 additions and 1 deletions
+29
View File
@@ -16,6 +16,8 @@ import {
grabForwardedBody,
livinDirectBody,
livinForwardedBody,
tokopediaMultiForwardedBody,
tokopediaSingleForwardedBody,
} from "./fixtures.js";
const silentLog = {
@@ -184,6 +186,33 @@ describe("matchRule", () => {
assert.equal(result.pass.rule.kind, "bri.qris.success");
});
it("matches forwarded Tokopedia Pesanan Selesai", async () => {
const result = await matchRule({
messageId: "1a09ba1248c7d2e8",
log: silentLog,
message: {
from: "NSRB <nasyarobby@gmail.com>",
subject: "Fwd: Pesanan Selesai: “Mouse Pad Besar Anime Style...”",
body: tokopediaSingleForwardedBody,
},
});
assert.equal(result.pass.rule.kind, "tokopedia.order.completed");
});
it("matches multi-item Tokopedia subject via original header", async () => {
const result = await matchRule({
messageId: "1a09ba315b65f2a5",
log: silentLog,
message: {
from: "NSRB <nasyarobby@gmail.com>",
subject:
"Fwd: Pesanan Selesai: “sandal jepit ANDA pria casual...” dan 1 Item Lainnya",
body: tokopediaMultiForwardedBody,
},
});
assert.equal(result.pass.rule.kind, "tokopedia.order.completed");
});
it("breaks on unknown from/subject", async () => {
const result = await matchRule({
messageId: "x",