From 12283fa6728b2818bb8d8670aa3172e00489fc45 Mon Sep 17 00:00:00 2001 From: Shakker Date: Sun, 10 May 2026 19:18:44 +0100 Subject: [PATCH] test: tighten mattermost send option assertions --- extensions/mattermost/src/channel.test.ts | 77 +++++++++-------------- 1 file changed, 29 insertions(+), 48 deletions(-) diff --git a/extensions/mattermost/src/channel.test.ts b/extensions/mattermost/src/channel.test.ts index 9e6bf9a60f4..54d95d20e4e 100644 --- a/extensions/mattermost/src/channel.test.ts +++ b/extensions/mattermost/src/channel.test.ts @@ -103,6 +103,17 @@ function createMattermostActionContext( }; } +function expectSingleMattermostSend(to: string, text: string): Record { + expect(sendMessageMattermostMock).toHaveBeenCalledTimes(1); + const [actualTo, actualText, options] = sendMessageMattermostMock.mock.calls[0] ?? []; + expect(actualTo).toBe(to); + expect(actualText).toBe(text); + if (!options || typeof options !== "object" || Array.isArray(options)) { + throw new Error("expected Mattermost send options object"); + } + return options as Record; +} + describe("mattermostPlugin", () => { beforeEach(() => { sendMessageMattermostMock.mockReset(); @@ -407,14 +418,9 @@ describe("mattermostPlugin", () => { }), ); - expect(sendMessageMattermostMock).toHaveBeenCalledWith( - "channel:CHAN1", - "hello", - expect.objectContaining({ - accountId: "default", - replyToId: "post-root", - }), - ); + const options = expectSingleMattermostSend("channel:CHAN1", "hello"); + expect(options.accountId).toBe("default"); + expect(options.replyToId).toBe("post-root"); }); it("falls back to trimmed replyTo when replyToId is blank", async () => { @@ -434,14 +440,9 @@ describe("mattermostPlugin", () => { }), ); - expect(sendMessageMattermostMock).toHaveBeenCalledWith( - "channel:CHAN1", - "hello", - expect.objectContaining({ - accountId: "default", - replyToId: "post-root", - }), - ); + const options = expectSingleMattermostSend("channel:CHAN1", "hello"); + expect(options.accountId).toBe("default"); + expect(options.replyToId).toBe("post-root"); }); }); @@ -468,14 +469,9 @@ describe("mattermostPlugin", () => { await sendMedia(params); - expect(sendMessageMattermostMock).toHaveBeenCalledWith( - "channel:CHAN1", - "hello", - expect.objectContaining({ - mediaUrl: "/tmp/workspace/image.png", - mediaLocalRoots: ["/tmp/workspace"], - }), - ); + const options = expectSingleMattermostSend("channel:CHAN1", "hello"); + expect(options.mediaUrl).toBe("/tmp/workspace/image.png"); + expect(options.mediaLocalRoots).toStrictEqual(["/tmp/workspace"]); }); it("threads resolved cfg on sendText", async () => { @@ -498,14 +494,9 @@ describe("mattermostPlugin", () => { await sendText(params); - expect(sendMessageMattermostMock).toHaveBeenCalledWith( - "channel:CHAN1", - "hello", - expect.objectContaining({ - cfg, - accountId: "default", - }), - ); + const options = expectSingleMattermostSend("channel:CHAN1", "hello"); + expect(options.cfg).toBe(cfg); + expect(options.accountId).toBe("default"); }); it("uses threadId as fallback when replyToId is absent (sendText)", async () => { @@ -522,14 +513,9 @@ describe("mattermostPlugin", () => { await sendText(params); - expect(sendMessageMattermostMock).toHaveBeenCalledWith( - "channel:CHAN1", - "hello", - expect.objectContaining({ - accountId: "default", - replyToId: "post-root", - }), - ); + const options = expectSingleMattermostSend("channel:CHAN1", "hello"); + expect(options.accountId).toBe("default"); + expect(options.replyToId).toBe("post-root"); }); it("uses threadId as fallback when replyToId is absent (sendMedia)", async () => { @@ -547,14 +533,9 @@ describe("mattermostPlugin", () => { await sendMedia(params); - expect(sendMessageMattermostMock).toHaveBeenCalledWith( - "channel:CHAN1", - "caption", - expect.objectContaining({ - accountId: "default", - replyToId: "post-root", - }), - ); + const options = expectSingleMattermostSend("channel:CHAN1", "caption"); + expect(options.accountId).toBe("default"); + expect(options.replyToId).toBe("post-root"); }); });