|
1 | 1 | jest.resetModules(); |
2 | 2 |
|
| 3 | +const mockFetchSuccess = () => |
| 4 | + jest.doMock("node-fetch", () => |
| 5 | + jest.fn(async () => ({ |
| 6 | + ok: true, |
| 7 | + buffer: async () => Buffer.from("imgdata"), |
| 8 | + })) |
| 9 | + ); |
| 10 | + |
| 11 | +mockFetchSuccess(); |
| 12 | + |
3 | 13 | // Mock deps |
4 | 14 | jest.doMock("../../../../bot/utils/groupMessageValidator", () => ({ |
5 | 15 | groupMessageValidator: jest.fn().mockResolvedValue(true), |
@@ -75,7 +85,7 @@ test("photo message gets file and included in photoUrls", async () => { |
75 | 85 | }; |
76 | 86 | const _ctx = await runHandler(message); |
77 | 87 | expect(sendToPerplexity).toHaveBeenCalledWith("with photo", [ |
78 | | - "https://api.telegram.org/file/botTOKEN/path.jpg", |
| 88 | + "data:image/jpeg;base64,aW1nZGF0YQ==", |
79 | 89 | ]); |
80 | 90 | }); |
81 | 91 |
|
@@ -197,6 +207,7 @@ test("error response from sendToPerplexity triggers editMessageText with error e |
197 | 207 | }; |
198 | 208 | // re-require module to use overwritten sendToPerplexity |
199 | 209 | jest.resetModules(); |
| 210 | + mockFetchSuccess(); |
200 | 211 | jest.doMock("../../../../bot/utils/groupMessageValidator", () => ({ |
201 | 212 | groupMessageValidator: jest.fn().mockResolvedValue(true), |
202 | 213 | })); |
@@ -224,6 +235,7 @@ test("error response from sendToPerplexity triggers editMessageText with error e |
224 | 235 | test("processing error triggers fallback reply and fallback sendMessage in processMessage", async () => { |
225 | 236 | // simulate sendToPerplexity throwing inside processMessage to hit fallback sendMessage |
226 | 237 | jest.resetModules(); |
| 238 | + mockFetchSuccess(); |
227 | 239 | jest.doMock("../../../../bot/utils/groupMessageValidator", () => ({ |
228 | 240 | groupMessageValidator: jest.fn().mockResolvedValue(true), |
229 | 241 | })); |
@@ -278,6 +290,7 @@ test("processing error triggers fallback reply and fallback sendMessage in proce |
278 | 290 |
|
279 | 291 | test("splits long response into multiple chunks and sends subsequent messages", async () => { |
280 | 292 | jest.resetModules(); |
| 293 | + mockFetchSuccess(); |
281 | 294 | jest.doMock("../../../../bot/utils/groupMessageValidator", () => ({ |
282 | 295 | groupMessageValidator: jest.fn().mockResolvedValue(true), |
283 | 296 | })); |
@@ -364,6 +377,7 @@ test("private chat returns next() immediately", async () => { |
364 | 377 |
|
365 | 378 | test("exact-command reaction callApi throws but does not call perplexity", async () => { |
366 | 379 | jest.resetModules(); |
| 380 | + mockFetchSuccess(); |
367 | 381 | jest.doMock("../../../../bot/utils/groupMessageValidator", () => ({ |
368 | 382 | groupMessageValidator: jest.fn().mockResolvedValue(true), |
369 | 383 | })); |
@@ -408,6 +422,7 @@ test("exact-command reaction callApi throws but does not call perplexity", async |
408 | 422 |
|
409 | 423 | test("photo getFile throws and processing continues without photoUrls", async () => { |
410 | 424 | jest.resetModules(); |
| 425 | + mockFetchSuccess(); |
411 | 426 | jest.doMock("../../../../bot/utils/groupMessageValidator", () => ({ |
412 | 427 | groupMessageValidator: jest.fn().mockResolvedValue(true), |
413 | 428 | })); |
@@ -465,6 +480,7 @@ test("photo getFile throws and processing continues without photoUrls", async () |
465 | 480 |
|
466 | 481 | test("media_group processing logs error when processing throws inside timeout", async () => { |
467 | 482 | jest.resetModules(); |
| 483 | + mockFetchSuccess(); |
468 | 484 | jest.doMock("../../../../bot/utils/groupMessageValidator", () => ({ |
469 | 485 | groupMessageValidator: jest.fn().mockResolvedValue(true), |
470 | 486 | })); |
@@ -540,6 +556,7 @@ test("media_group processing logs error when processing throws inside timeout", |
540 | 556 |
|
541 | 557 | test("processMessage handles errorEntry for media_group by editing message with error text", async () => { |
542 | 558 | jest.resetModules(); |
| 559 | + mockFetchSuccess(); |
543 | 560 | jest.doMock("../../../../bot/utils/groupMessageValidator", () => ({ |
544 | 561 | groupMessageValidator: jest.fn().mockResolvedValue(true), |
545 | 562 | })); |
@@ -619,6 +636,7 @@ test("processMessage handles errorEntry for media_group by editing message with |
619 | 636 |
|
620 | 637 | test("processMessage splits long response into chunks for media_group and sends subsequent messages", async () => { |
621 | 638 | jest.resetModules(); |
| 639 | + mockFetchSuccess(); |
622 | 640 | jest.doMock("../../../../bot/utils/groupMessageValidator", () => ({ |
623 | 641 | groupMessageValidator: jest.fn().mockResolvedValue(true), |
624 | 642 | })); |
@@ -699,6 +717,7 @@ test("processMessage splits long response into chunks for media_group and sends |
699 | 717 |
|
700 | 718 | test("top-level handler fallback reply when sendToPerplexity throws", async () => { |
701 | 719 | jest.resetModules(); |
| 720 | + mockFetchSuccess(); |
702 | 721 | jest.doMock("../../../../bot/utils/groupMessageValidator", () => ({ |
703 | 722 | groupMessageValidator: jest.fn().mockResolvedValue(true), |
704 | 723 | })); |
@@ -753,6 +772,7 @@ test("top-level handler fallback reply when sendToPerplexity throws", async () = |
753 | 772 |
|
754 | 773 | test("top-level nested fallback logs error when ctx.reply also throws", async () => { |
755 | 774 | jest.resetModules(); |
| 775 | + mockFetchSuccess(); |
756 | 776 | jest.doMock("../../../../bot/utils/groupMessageValidator", () => ({ |
757 | 777 | groupMessageValidator: jest.fn().mockResolvedValue(true), |
758 | 778 | })); |
@@ -811,6 +831,7 @@ test("top-level nested fallback logs error when ctx.reply also throws", async () |
811 | 831 |
|
812 | 832 | test("processMessage nested fallback logs error when fallback sendMessage throws", async () => { |
813 | 833 | jest.resetModules(); |
| 834 | + mockFetchSuccess(); |
814 | 835 | jest.doMock("../../../../bot/utils/groupMessageValidator", () => ({ |
815 | 836 | groupMessageValidator: jest.fn().mockResolvedValue(true), |
816 | 837 | })); |
@@ -892,6 +913,7 @@ test("processMessage nested fallback logs error when fallback sendMessage throws |
892 | 913 |
|
893 | 914 | test("direct call to _processMessage edits message when errorEntry returned", async () => { |
894 | 915 | jest.resetModules(); |
| 916 | + mockFetchSuccess(); |
895 | 917 | jest.doMock("../../../../bot/utils/groupMessageValidator", () => ({ |
896 | 918 | groupMessageValidator: jest.fn().mockResolvedValue(true), |
897 | 919 | })); |
@@ -925,6 +947,7 @@ test("direct call to _processMessage edits message when errorEntry returned", as |
925 | 947 |
|
926 | 948 | test("direct call to _processMessage logs error when fallback sendMessage throws", async () => { |
927 | 949 | jest.resetModules(); |
| 950 | + mockFetchSuccess(); |
928 | 951 | jest.doMock("../../../../bot/utils/groupMessageValidator", () => ({ |
929 | 952 | groupMessageValidator: jest.fn().mockResolvedValue(true), |
930 | 953 | })); |
|
0 commit comments