Show invited people the Rule, let them copy its cards for their community, and replace an expired invitation link.

This commit is contained in:
adilallo committed 2026-11-06 09:16:06 -07:00
1 parent 727a92a9ac
commit 3c984e00c5
37 files changed
+1962 -19

No files matched your search

@@ -70,7 +70,7 @@ describe("GET /api/invites/rule-stakeholder/verify", () => {
expect(res.status).toBeGreaterThanOrEqual(300);
expect(res.status).toBeLessThan(400);
expect(res.headers.get("location")).toContain("/rules/rule-1");
expect(res.headers.get("location")).toContain("/invite/rule-1");
expect(setCookieMock).toHaveBeenCalled();
});
@@ -97,4 +97,50 @@ describe("GET /api/invites/rule-stakeholder/verify", () => {
);
expect(upsertMock).not.toHaveBeenCalled();
});
it("redirects expired tokens to the expired invitation page", async () => {
getSessionUserMock.mockResolvedValue(null);
findUniqueMock.mockResolvedValue({
id: "st1",
email: "inv@example.com",
ruleId: "rule-1",
inviteExpiresAt: new Date(Date.now() - 60_000),
});
const token = "z".repeat(12);
const res = await GET(
new NextRequest(
`https://x.test/api/invites/rule-stakeholder/verify?token=${token}`,
),
);
expect(res.headers.get("location")).toContain("/invite/expired");
expect(res.headers.get("location")).toContain(`token=${token}`);
expect(upsertMock).not.toHaveBeenCalled();
});
it("keeps copy=1 on the invited view after a valid token", async () => {
getSessionUserMock.mockResolvedValue(null);
findUniqueMock.mockResolvedValue({
id: "st1",
email: "inv@example.com",
ruleId: "rule-1",
inviteExpiresAt: new Date(Date.now() + 60_000),
});
upsertMock.mockResolvedValue({ id: "u1", email: "inv@example.com" });
updateMock.mockResolvedValue({});
createSessionMock.mockResolvedValue({
token: "sess",
expiresAt: new Date(),
});
const res = await GET(
new NextRequest(
`https://x.test/api/invites/rule-stakeholder/verify?token=${"x".repeat(12)}&copy=1`,
),
);
expect(res.headers.get("location")).toContain("/invite/rule-1");
expect(res.headers.get("location")).toContain("copy=1");
});
});