Keep a published rule when some invitation emails already went out, and only set Reply-To when the inviter address is a mailbox.

This commit is contained in:
adilallo committed 2026-11-06 09:22:06 -07:00
1 parent 3c984e00c5
commit ab6a0c807d
7 files changed
+161 -10

No files matched your search

+49
View File
@@ -202,6 +202,55 @@ describe("POST /api/rules", () => {
});
});
it("keeps the rule when a later invite send fails after one succeeded", async () => {
const created = {
id: "rule-partial",
title: "Published title",
summary: null,
createdAt: new Date("2026-01-02T00:00:00.000Z"),
};
transactionMock.mockImplementation(
async (
fn: (tx: {
publishedRule: { create: typeof vi.fn };
ruleStakeholder: { create: typeof vi.fn };
}) => Promise<unknown>,
) => {
const tx = {
publishedRule: {
create: vi.fn().mockResolvedValue(created),
},
ruleStakeholder: {
create: vi.fn().mockResolvedValue({}),
},
};
return fn(tx);
},
);
sendInviteMock
.mockResolvedValueOnce(undefined)
.mockRejectedValueOnce(new Error("smtp down"));
const res = await POST(
new NextRequest("https://x.test/api/rules", {
method: "POST",
body: JSON.stringify({
title: "Published title",
summary: null,
document: {},
stakeholderEmails: ["first@example.com", "second@example.com"],
}),
}),
undefined,
);
expect(res.status).toBe(200);
expect(sendInviteMock).toHaveBeenCalledTimes(2);
expect(publishedRuleDeleteMock).not.toHaveBeenCalled();
const body = (await res.json()) as { rule: { id: string } };
expect(body.rule.id).toBe("rule-partial");
});
it("creates an unlisted rule when there is no session", async () => {
getSessionUserMock.mockResolvedValueOnce(null);
publishedRuleCreateMock.mockResolvedValueOnce({