Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions __tests__/commands/notifications.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down
2 changes: 2 additions & 0 deletions src/commands/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const notificationsCommand = new Command("notifications")
.option("--html <body>", "Raw HTML body (takes precedence over --text)")
.option("--cc <email>", "CC recipient (repeatable)", (val: string, prev: string[]) => prev.concat(val), [] as string[])
.option("--room-id <id>", "Room ID for chat link in footer")
.option("--account <accountId>", "Send to a specific account (org keys only)")
.option("--json", "Output as JSON")
.action(async (opts) => {
try {
Expand All @@ -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);

Expand Down