mirror of https://github.com/openclaw/openclaw.git
test(ci): mock googlechat action media loader
This commit is contained in:
parent
8bf8baef87
commit
35c6b3f648
|
|
@ -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({
|
||||
|
|
|
|||
Loading…
Reference in New Issue