From 0b9a9e05f72b6b293a15800910c2972249456f1c Mon Sep 17 00:00:00 2001 From: Sweets Sweetman Date: Wed, 25 Feb 2026 11:43:10 -0500 Subject: [PATCH] feat: add --account flag to notifications command Passes account_id in POST body so org keys can send notifications on behalf of member accounts. Co-Authored-By: Claude Opus 4.6 --- __tests__/commands/notifications.test.ts | 43 ++++++++++++++++++++++++ src/commands/notifications.ts | 2 ++ 2 files changed, 45 insertions(+) diff --git a/__tests__/commands/notifications.test.ts b/__tests__/commands/notifications.test.ts index 974f61b..fd577e9 100644 --- a/__tests__/commands/notifications.test.ts +++ b/__tests__/commands/notifications.test.ts @@ -134,6 +134,49 @@ describe("notifications command", () => { ); }); + it("passes account_id when --account flag is provided", async () => { + vi.mocked(post).mockResolvedValue({ + success: true, + message: "Email sent successfully.", + id: "email-account", + }); + + await notificationsCommand.parseAsync( + [ + "--subject", + "Override Test", + "--text", + "Hello member", + "--account", + "550e8400-e29b-41d4-a716-446655440000", + ], + { from: "user" }, + ); + + expect(post).toHaveBeenCalledWith("/api/notifications", { + subject: "Override Test", + text: "Hello member", + account_id: "550e8400-e29b-41d4-a716-446655440000", + }); + }); + + it("does not include account_id when --account is omitted", async () => { + vi.mocked(post).mockResolvedValue({ + success: true, + message: "Email sent successfully.", + id: "email-no-account", + }); + + await notificationsCommand.parseAsync( + ["--subject", "Test"], + { from: "user" }, + ); + + expect(post).toHaveBeenCalledWith("/api/notifications", { + subject: "Test", + }); + }); + it("prints error on failure", async () => { vi.mocked(post).mockRejectedValue(new Error("No email address found")); diff --git a/src/commands/notifications.ts b/src/commands/notifications.ts index f79e6e6..5e33011 100644 --- a/src/commands/notifications.ts +++ b/src/commands/notifications.ts @@ -9,6 +9,7 @@ export const notificationsCommand = new Command("notifications") .option("--html ", "Raw HTML body (takes precedence over --text)") .option("--cc ", "CC recipient (repeatable)", (val: string, prev: string[]) => prev.concat(val), [] as string[]) .option("--room-id ", "Room ID for chat link in footer") + .option("--account ", "Send to a specific account (org keys only)") .option("--json", "Output as JSON") .action(async (opts) => { try { @@ -19,6 +20,7 @@ export const notificationsCommand = new Command("notifications") if (opts.html) body.html = opts.html; if (opts.cc && opts.cc.length > 0) body.cc = opts.cc; if (opts.roomId) body.room_id = opts.roomId; + if (opts.account) body.account_id = opts.account; const data = await post("/api/notifications", body);