mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 15:34:46 +00:00
test: tighten mattermost send option assertions
This commit is contained in:
@@ -103,6 +103,17 @@ function createMattermostActionContext(
|
||||
};
|
||||
}
|
||||
|
||||
function expectSingleMattermostSend(to: string, text: string): Record<string, unknown> {
|
||||
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<string, unknown>;
|
||||
}
|
||||
|
||||
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");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user