mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 08:17:40 +00:00
test(web): dedupe media-failure setup in deliver reply tests
This commit is contained in:
@@ -37,6 +37,22 @@ function makeMsg(): WebInboundMsg {
|
|||||||
} as unknown as WebInboundMsg;
|
} as unknown as WebInboundMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mockLoadedImageMedia() {
|
||||||
|
(
|
||||||
|
loadWebMedia as unknown as { mockResolvedValueOnce: (v: unknown) => void }
|
||||||
|
).mockResolvedValueOnce({
|
||||||
|
buffer: Buffer.from("img"),
|
||||||
|
contentType: "image/jpeg",
|
||||||
|
kind: "image",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function mockFirstSendMediaFailure(msg: WebInboundMsg, message: string) {
|
||||||
|
(
|
||||||
|
msg.sendMedia as unknown as { mockRejectedValueOnce: (v: unknown) => void }
|
||||||
|
).mockRejectedValueOnce(new Error(message));
|
||||||
|
}
|
||||||
|
|
||||||
const replyLogger = {
|
const replyLogger = {
|
||||||
info: vi.fn(),
|
info: vi.fn(),
|
||||||
warn: vi.fn(),
|
warn: vi.fn(),
|
||||||
@@ -123,16 +139,8 @@ describe("deliverWebReply", () => {
|
|||||||
|
|
||||||
it("retries media send on transient failure", async () => {
|
it("retries media send on transient failure", async () => {
|
||||||
const msg = makeMsg();
|
const msg = makeMsg();
|
||||||
(
|
mockLoadedImageMedia();
|
||||||
loadWebMedia as unknown as { mockResolvedValueOnce: (v: unknown) => void }
|
mockFirstSendMediaFailure(msg, "socket reset");
|
||||||
).mockResolvedValueOnce({
|
|
||||||
buffer: Buffer.from("img"),
|
|
||||||
contentType: "image/jpeg",
|
|
||||||
kind: "image",
|
|
||||||
});
|
|
||||||
(
|
|
||||||
msg.sendMedia as unknown as { mockRejectedValueOnce: (v: unknown) => void }
|
|
||||||
).mockRejectedValueOnce(new Error("socket reset"));
|
|
||||||
(
|
(
|
||||||
msg.sendMedia as unknown as { mockResolvedValueOnce: (v: unknown) => void }
|
msg.sendMedia as unknown as { mockResolvedValueOnce: (v: unknown) => void }
|
||||||
).mockResolvedValueOnce(undefined);
|
).mockResolvedValueOnce(undefined);
|
||||||
@@ -152,16 +160,8 @@ describe("deliverWebReply", () => {
|
|||||||
|
|
||||||
it("falls back to text-only when the first media send fails", async () => {
|
it("falls back to text-only when the first media send fails", async () => {
|
||||||
const msg = makeMsg();
|
const msg = makeMsg();
|
||||||
(
|
mockLoadedImageMedia();
|
||||||
loadWebMedia as unknown as { mockResolvedValueOnce: (v: unknown) => void }
|
mockFirstSendMediaFailure(msg, "boom");
|
||||||
).mockResolvedValueOnce({
|
|
||||||
buffer: Buffer.from("img"),
|
|
||||||
contentType: "image/jpeg",
|
|
||||||
kind: "image",
|
|
||||||
});
|
|
||||||
(
|
|
||||||
msg.sendMedia as unknown as { mockRejectedValueOnce: (v: unknown) => void }
|
|
||||||
).mockRejectedValueOnce(new Error("boom"));
|
|
||||||
|
|
||||||
await deliverWebReply({
|
await deliverWebReply({
|
||||||
replyResult: { text: "caption", mediaUrl: "http://example.com/img.jpg" },
|
replyResult: { text: "caption", mediaUrl: "http://example.com/img.jpg" },
|
||||||
|
|||||||
Reference in New Issue
Block a user