|
2 | 2 | import { Command } from "commander"; |
3 | 3 | import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures"; |
4 | 4 | import { beforeEach, describe, expect, it, vi } from "vitest"; |
| 5 | +import { registerMessagePollCommand } from "./register.poll.js"; |
| 6 | +import { registerMessageReactionsCommands } from "./register.reactions.js"; |
| 7 | +import { registerMessageReadEditDeleteCommands } from "./register.read-edit-delete.js"; |
5 | 8 | import { registerMessageSendCommand } from "./register.send.js"; |
6 | 9 |
|
7 | 10 | const messageCommandMock = vi.fn(async (): Promise<unknown> => undefined); |
@@ -212,6 +215,64 @@ describe("runMessageAction", () => { |
212 | 215 | }, |
213 | 216 | ); |
214 | 217 |
|
| 218 | + it.each([ |
| 219 | + ["disabled reaction", "react", { ok: false, hint: "Reactions are disabled." }, 1], |
| 220 | + ["rejected added reaction", "react", { ok: false, warning: "Unavailable", added: "✅" }, 1], |
| 221 | + ["rejected delete", "delete", { ok: false, deleted: false, warning: "Not deleted" }, 1], |
| 222 | + ["rejected poll", "poll", { ok: false, error: "Poll rejected" }, 1], |
| 223 | + ["rejected send", "send", { ok: false, error: "Message rejected" }, 1], |
| 224 | + ["successful reaction", "react", { ok: true, added: "✅" }, 0], |
| 225 | + ["legacy reaction", "react", { added: "✅" }, 0], |
| 226 | + ["non-boolean outcome", "react", { ok: "false", added: "✅" }, 0], |
| 227 | + ["dry-run", "react", { ok: false, error: "Not executed" }, 0], |
| 228 | + ] as const)( |
| 229 | + "propagates %s through the real CLI parser", |
| 230 | + async (name, action, payload, exitCode) => { |
| 231 | + const dryRun = name === "dry-run"; |
| 232 | + const kind = action === "send" || action === "poll" ? action : "action"; |
| 233 | + messageCommandMock.mockResolvedValueOnce({ |
| 234 | + kind, |
| 235 | + channel: "telegram", |
| 236 | + action, |
| 237 | + ...(kind === "action" ? {} : { to: "123" }), |
| 238 | + handledBy: "plugin", |
| 239 | + payload, |
| 240 | + dryRun, |
| 241 | + }); |
| 242 | + const program = new Command(); |
| 243 | + const message = program.command("message"); |
| 244 | + const helpers = createMessageCliHelpers(message, "telegram"); |
| 245 | + registerMessageSendCommand(message, helpers); |
| 246 | + registerMessagePollCommand(message, helpers); |
| 247 | + registerMessageReactionsCommands(message, helpers); |
| 248 | + registerMessageReadEditDeleteCommands(message, helpers); |
| 249 | + const args = { |
| 250 | + react: ["--message-id", "456", "--emoji", "✅"], |
| 251 | + delete: ["--message-id", "456"], |
| 252 | + poll: ["--poll-question", "Ready?", "--poll-option", "Yes", "--poll-option", "No"], |
| 253 | + send: ["--message", "hello"], |
| 254 | + }[action]; |
| 255 | + |
| 256 | + await expect( |
| 257 | + program.parseAsync( |
| 258 | + [ |
| 259 | + "message", |
| 260 | + action, |
| 261 | + "--channel", |
| 262 | + "telegram", |
| 263 | + "--target", |
| 264 | + "123", |
| 265 | + ...args, |
| 266 | + ...(dryRun ? ["--dry-run"] : []), |
| 267 | + ], |
| 268 | + { from: "user" }, |
| 269 | + ), |
| 270 | + ).rejects.toThrow("exit"); |
| 271 | + |
| 272 | + expect(exitMock).toHaveBeenCalledWith(exitCode); |
| 273 | + }, |
| 274 | + ); |
| 275 | + |
215 | 276 | it("loads configured channel plugins when no target channel is known yet", async () => { |
216 | 277 | await runSendAction({ channel: undefined }); |
217 | 278 |
|
|
0 commit comments