


























@@ -103,6 +103,17 @@ function createMattermostActionContext(
103103};
104104}
105105106+function expectSingleMattermostSend(to: string, text: string): Record<string, unknown> {
107+expect(sendMessageMattermostMock).toHaveBeenCalledTimes(1);
108+const [actualTo, actualText, options] = sendMessageMattermostMock.mock.calls[0] ?? [];
109+expect(actualTo).toBe(to);
110+expect(actualText).toBe(text);
111+if (!options || typeof options !== "object" || Array.isArray(options)) {
112+throw new Error("expected Mattermost send options object");
113+}
114+return options as Record<string, unknown>;
115+}
116+106117describe("mattermostPlugin", () => {
107118beforeEach(() => {
108119sendMessageMattermostMock.mockReset();
@@ -407,14 +418,9 @@ describe("mattermostPlugin", () => {
407418}),
408419);
409420410-expect(sendMessageMattermostMock).toHaveBeenCalledWith(
411-"channel:CHAN1",
412-"hello",
413-expect.objectContaining({
414-accountId: "default",
415-replyToId: "post-root",
416-}),
417-);
421+const options = expectSingleMattermostSend("channel:CHAN1", "hello");
422+expect(options.accountId).toBe("default");
423+expect(options.replyToId).toBe("post-root");
418424});
419425420426it("falls back to trimmed replyTo when replyToId is blank", async () => {
@@ -434,14 +440,9 @@ describe("mattermostPlugin", () => {
434440}),
435441);
436442437-expect(sendMessageMattermostMock).toHaveBeenCalledWith(
438-"channel:CHAN1",
439-"hello",
440-expect.objectContaining({
441-accountId: "default",
442-replyToId: "post-root",
443-}),
444-);
443+const options = expectSingleMattermostSend("channel:CHAN1", "hello");
444+expect(options.accountId).toBe("default");
445+expect(options.replyToId).toBe("post-root");
445446});
446447});
447448@@ -468,14 +469,9 @@ describe("mattermostPlugin", () => {
468469469470await sendMedia(params);
470471471-expect(sendMessageMattermostMock).toHaveBeenCalledWith(
472-"channel:CHAN1",
473-"hello",
474-expect.objectContaining({
475-mediaUrl: "/tmp/workspace/image.png",
476-mediaLocalRoots: ["/tmp/workspace"],
477-}),
478-);
472+const options = expectSingleMattermostSend("channel:CHAN1", "hello");
473+expect(options.mediaUrl).toBe("/tmp/workspace/image.png");
474+expect(options.mediaLocalRoots).toStrictEqual(["/tmp/workspace"]);
479475});
480476481477it("threads resolved cfg on sendText", async () => {
@@ -498,14 +494,9 @@ describe("mattermostPlugin", () => {
498494499495await sendText(params);
500496501-expect(sendMessageMattermostMock).toHaveBeenCalledWith(
502-"channel:CHAN1",
503-"hello",
504-expect.objectContaining({
505- cfg,
506-accountId: "default",
507-}),
508-);
497+const options = expectSingleMattermostSend("channel:CHAN1", "hello");
498+expect(options.cfg).toBe(cfg);
499+expect(options.accountId).toBe("default");
509500});
510501511502it("uses threadId as fallback when replyToId is absent (sendText)", async () => {
@@ -522,14 +513,9 @@ describe("mattermostPlugin", () => {
522513523514await sendText(params);
524515525-expect(sendMessageMattermostMock).toHaveBeenCalledWith(
526-"channel:CHAN1",
527-"hello",
528-expect.objectContaining({
529-accountId: "default",
530-replyToId: "post-root",
531-}),
532-);
516+const options = expectSingleMattermostSend("channel:CHAN1", "hello");
517+expect(options.accountId).toBe("default");
518+expect(options.replyToId).toBe("post-root");
533519});
534520535521it("uses threadId as fallback when replyToId is absent (sendMedia)", async () => {
@@ -547,14 +533,9 @@ describe("mattermostPlugin", () => {
547533548534await sendMedia(params);
549535550-expect(sendMessageMattermostMock).toHaveBeenCalledWith(
551-"channel:CHAN1",
552-"caption",
553-expect.objectContaining({
554-accountId: "default",
555-replyToId: "post-root",
556-}),
557-);
536+const options = expectSingleMattermostSend("channel:CHAN1", "caption");
537+expect(options.accountId).toBe("default");
538+expect(options.replyToId).toBe("post-root");
558539});
559540});
560541此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。