test(ci): mock googlechat action media loader

This commit is contained in:
Vincent Koc 2026-04-01 01:29:50 +09:00
parent 8bf8baef87
commit 35c6b3f648
1 changed files with 14 additions and 7 deletions

View File

@ -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<typeof import("../runtime-api.js")>();
return {
...actual,
loadOutboundMediaFromUrl: (...args: Parameters<typeof actual.loadOutboundMediaFromUrl>) =>
(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({