diff --git a/extensions/googlechat/src/actions.test.ts b/extensions/googlechat/src/actions.test.ts index a12566928a0..79960f89341 100644 --- a/extensions/googlechat/src/actions.test.ts +++ b/extensions/googlechat/src/actions.test.ts @@ -9,6 +9,7 @@ const sendGoogleChatMessage = vi.hoisted(() => vi.fn()); const uploadGoogleChatAttachment = vi.hoisted(() => vi.fn()); const resolveGoogleChatOutboundSpace = vi.hoisted(() => vi.fn()); const getGoogleChatRuntime = vi.hoisted(() => vi.fn()); +const loadOutboundMediaFromUrl = vi.hoisted(() => vi.fn()); vi.mock("./accounts.js", () => ({ listEnabledGoogleChatAccounts, @@ -31,6 +32,15 @@ vi.mock("./targets.js", () => ({ resolveGoogleChatOutboundSpace, })); +vi.mock("../runtime-api.js", async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + loadOutboundMediaFromUrl: (...args: Parameters) => + (loadOutboundMediaFromUrl as unknown as typeof actual.loadOutboundMediaFromUrl)(...args), + }; +}); + let googlechatMessageActions: typeof import("./actions.js").googlechatMessageActions; describe("googlechat message actions", () => { @@ -130,20 +140,17 @@ describe("googlechat message actions", () => { config: { mediaMaxMb: 5 }, }); resolveGoogleChatOutboundSpace.mockResolvedValue("spaces/BBB"); - const loadWebMedia = vi.fn(async () => ({ + loadOutboundMediaFromUrl.mockResolvedValue({ buffer: Buffer.from("local-bytes"), fileName: "local.txt", contentType: "text/plain", - })); + }); getGoogleChatRuntime.mockReturnValue({ channel: { media: { fetchRemoteMedia: vi.fn(), }, }, - media: { - loadWebMedia, - }, }); uploadGoogleChatAttachment.mockResolvedValue({ attachmentUploadToken: "token-2", @@ -168,9 +175,9 @@ describe("googlechat message actions", () => { mediaLocalRoots: ["/tmp"], } as never); - expect(loadWebMedia).toHaveBeenCalledWith( + expect(loadOutboundMediaFromUrl).toHaveBeenCalledWith( "/tmp/local.txt", - expect.objectContaining({ localRoots: ["/tmp"] }), + expect.objectContaining({ mediaLocalRoots: ["/tmp"] }), ); expect(uploadGoogleChatAttachment).toHaveBeenCalledWith( expect.objectContaining({