accounting_automation: инвойс в письме в любом виде (тело, вложения любых типов, zip); тесты; approved и snapshot документов
All checks were successful
ci / test (push) Successful in 45s
ci / deploy (push) Successful in 2m44s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 18:07:57 +03:00
parent a274c9c163
commit d6d203dea3
254 changed files with 3788 additions and 50 deletions

View File

@@ -65,16 +65,17 @@ describe("Gmail: разбор ответов", () => {
},
};
it("parseGmailMessage: заголовки, PDF-вложения, дата", async () => {
it("parseGmailMessage: заголовки, вложения любых типов, тело письма, дата", async () => {
const m = parseGmailMessage(msgJson, async (id) => Buffer.from(`bytes-${id}`));
expect(m).toMatchObject({ id: "m1", from: "Bob <bob@vendor.com>", subject: "Invoice 42" });
expect(m.receivedAt.toISOString()).toBe("2026-01-01T00:00:00.000Z");
expect(m.attachments.map((a) => a.filename)).toEqual(["inv.pdf", "inline.PDF"]);
expect(m.attachments.map((a) => a.filename)).toEqual(["inv.pdf", "photo.jpg", "inline.PDF"]);
expect(m.bodyText).toBe("hi");
expect((await m.attachments[0].getBytes()).toString()).toBe("bytes-att1");
expect((await m.attachments[1].getBytes()).toString()).toBe("PDFDATA");
expect((await m.attachments[2].getBytes()).toString()).toBe("PDFDATA");
});
it("GmailClient.listUnprocessed: пропускает обработанные, сторонние письма без PDF и берёт вложения", async () => {
it("GmailClient.listUnprocessed: пропускает обработанные, берёт все остальные письма (в том числе без вложений)", async () => {
const urls: string[] = [];
const fetchFn = (async (url: string, init: RequestInit) => {
urls.push(url);
@@ -92,9 +93,9 @@ describe("Gmail: разбор ответов", () => {
} } as unknown as GoogleAuth;
const c = new GmailClient({ auth, user: "invoices@khbuild.pro", processedIds: async () => new Set(["m0"]), fetchFn });
const list = await c.listUnprocessed(10);
expect(list.map((m) => m.id)).toEqual(["m1"]);
expect(list.map((m) => m.id)).toEqual(["m1", "m2"]);
expect((await list[0].attachments[0].getBytes()).toString()).toBe("PDF1");
expect(decodeURIComponent(urls[0])).toContain("q=has:attachment+filename:pdf".replace(/\+/g, "+"));
expect(decodeURIComponent(urls[0])).not.toContain("has:attachment");
});
});