test(telegram): harden media tests
This commit is contained in:
@@ -62,7 +62,12 @@ vi.mock("../auto-reply/reply.js", () => {
|
||||
});
|
||||
|
||||
describe("telegram inbound media", () => {
|
||||
it("downloads media via file_path (no file.download)", async () => {
|
||||
const INBOUND_MEDIA_TEST_TIMEOUT_MS =
|
||||
process.platform === "win32" ? 30_000 : 10_000;
|
||||
|
||||
it(
|
||||
"downloads media via file_path (no file.download)",
|
||||
async () => {
|
||||
const { createTelegramBot } = await import("./bot.js");
|
||||
const replyModule = await import("../auto-reply/reply.js");
|
||||
const replySpy = replyModule.__replySpy as unknown as ReturnType<
|
||||
@@ -121,7 +126,9 @@ describe("telegram inbound media", () => {
|
||||
expect(payload.Body).toContain("<media:image>");
|
||||
|
||||
fetchSpy.mockRestore();
|
||||
});
|
||||
},
|
||||
INBOUND_MEDIA_TEST_TIMEOUT_MS,
|
||||
);
|
||||
|
||||
it("prefers proxyFetch over global fetch", async () => {
|
||||
const { createTelegramBot } = await import("./bot.js");
|
||||
@@ -283,7 +290,7 @@ describe("telegram media groups", () => {
|
||||
)?.[1] as (ctx: Record<string, unknown>) => Promise<void>;
|
||||
expect(handler).toBeDefined();
|
||||
|
||||
await handler({
|
||||
const first = handler({
|
||||
message: {
|
||||
chat: { id: 42, type: "private" },
|
||||
message_id: 1,
|
||||
@@ -296,7 +303,7 @@ describe("telegram media groups", () => {
|
||||
getFile: async () => ({ file_path: "photos/photo1.jpg" }),
|
||||
});
|
||||
|
||||
await handler({
|
||||
const second = handler({
|
||||
message: {
|
||||
chat: { id: 42, type: "private" },
|
||||
message_id: 2,
|
||||
@@ -308,6 +315,8 @@ describe("telegram media groups", () => {
|
||||
getFile: async () => ({ file_path: "photos/photo2.jpg" }),
|
||||
});
|
||||
|
||||
await Promise.all([first, second]);
|
||||
|
||||
expect(replySpy).not.toHaveBeenCalled();
|
||||
await waitForMediaGroupProcessing(replySpy, 1);
|
||||
|
||||
@@ -351,7 +360,7 @@ describe("telegram media groups", () => {
|
||||
)?.[1] as (ctx: Record<string, unknown>) => Promise<void>;
|
||||
expect(handler).toBeDefined();
|
||||
|
||||
await handler({
|
||||
const first = handler({
|
||||
message: {
|
||||
chat: { id: 42, type: "private" },
|
||||
message_id: 1,
|
||||
@@ -364,7 +373,7 @@ describe("telegram media groups", () => {
|
||||
getFile: async () => ({ file_path: "photos/photoA1.jpg" }),
|
||||
});
|
||||
|
||||
await handler({
|
||||
const second = handler({
|
||||
message: {
|
||||
chat: { id: 42, type: "private" },
|
||||
message_id: 2,
|
||||
@@ -377,6 +386,8 @@ describe("telegram media groups", () => {
|
||||
getFile: async () => ({ file_path: "photos/photoB1.jpg" }),
|
||||
});
|
||||
|
||||
await Promise.all([first, second]);
|
||||
|
||||
expect(replySpy).not.toHaveBeenCalled();
|
||||
await waitForMediaGroupProcessing(replySpy, 2);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user