test(cli): cover send and gateway_stop failure path

This commit is contained in:
Gustavo Madeira Santana 2026-02-14 17:21:13 -05:00
parent bc1edeba33
commit b45d4dc388
1 changed files with 16 additions and 0 deletions

View File

@ -121,6 +121,22 @@ describe("runMessageAction", () => {
expect(exitMock).toHaveBeenCalledWith(0);
});
it("logs gateway_stop failure and preserves failure exit code when send fails", async () => {
hasHooksMock.mockReturnValueOnce(true);
messageCommandMock.mockRejectedValueOnce(new Error("send failed"));
runGatewayStopMock.mockRejectedValueOnce(new Error("hook failed"));
const fakeCommand = { help: vi.fn() } as never;
const { runMessageAction } = createMessageCliHelpers(fakeCommand, "discord");
await expect(
runMessageAction("send", { channel: "discord", target: "123", message: "hi" }),
).rejects.toThrow("exit");
expect(errorMock).toHaveBeenNthCalledWith(1, "Error: send failed");
expect(errorMock).toHaveBeenNthCalledWith(2, "gateway_stop hook failed: Error: hook failed");
expect(exitMock).toHaveBeenCalledWith(1);
});
it("does not call exit(0) when the action throws", async () => {
messageCommandMock.mockRejectedValueOnce(new Error("boom"));
const fakeCommand = { help: vi.fn() } as never;