Adds the notifications system end-to-end (4 types, payload-versioned JSONB, SSE-based live unread badge, /notifications page, mark-read API, fan-out job for activity_published, daily 90-day retention purge). Bell icon in the navbar with unread badge. Side-findings from exercising the change: - Add 6-digit magic code to registration (mirrors login UX, mobile paste-friendly), with `[Register Magic Link]` console line in dev so the code is reachable without a real email transport. - Manual passkey/magic-link toggle on the register form (login already had it). - Restrict ALPN to http/1.1 in HTTPS dev so React Router's singleFetchAction CSRF check (Origin vs. Host) passes — Node doesn't synthesize Host from h2's :authority. Plain HTTP dev unaffected. - Followers/Following routes now use the locked-account rule from the profile route (owner + accepted followers see the list; others 404). Profile page renders the count chips as plain spans for viewers who can't see the lists, so private profiles don't surface dead links. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
75 lines
2.3 KiB
TypeScript
75 lines
2.3 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { linkFor } from "./link-for.ts";
|
|
|
|
describe("linkFor", () => {
|
|
it("follow_received uses payload.followerUsername", () => {
|
|
const link = linkFor({
|
|
type: "follow_received",
|
|
subjectId: null,
|
|
payloadVersion: 1,
|
|
payload: { followerUsername: "alice", followerDisplayName: null },
|
|
});
|
|
expect(link.web).toBe("/users/alice");
|
|
expect(link.mobile).toBe("trails:/users/alice");
|
|
expect(link.email).toMatch(/^https?:\/\//);
|
|
expect(link.email).toMatch(/\/users\/alice$/);
|
|
});
|
|
|
|
it("follow_received falls back to / when payload is missing", () => {
|
|
const link = linkFor({
|
|
type: "follow_received",
|
|
subjectId: null,
|
|
payloadVersion: 1,
|
|
payload: null,
|
|
});
|
|
expect(link.web).toBe("/");
|
|
});
|
|
|
|
it("follow_request_received always points at the requests page", () => {
|
|
const link = linkFor({
|
|
type: "follow_request_received",
|
|
subjectId: null,
|
|
payloadVersion: 1,
|
|
payload: { followerUsername: "bob", followerDisplayName: null },
|
|
});
|
|
expect(link.web).toBe("/follows/requests");
|
|
});
|
|
|
|
it("follow_request_approved uses payload.targetUsername", () => {
|
|
const link = linkFor({
|
|
type: "follow_request_approved",
|
|
subjectId: null,
|
|
payloadVersion: 1,
|
|
payload: { targetUsername: "carol", targetDisplayName: null },
|
|
});
|
|
expect(link.web).toBe("/users/carol");
|
|
});
|
|
|
|
it("activity_published prefers subjectId, falls back to payload.activityId", () => {
|
|
const fromSubject = linkFor({
|
|
type: "activity_published",
|
|
subjectId: "sub-id-1",
|
|
payloadVersion: 1,
|
|
payload: { activityId: "payload-id", activityName: "x", ownerUsername: "o", ownerDisplayName: null },
|
|
});
|
|
expect(fromSubject.web).toBe("/activities/sub-id-1");
|
|
|
|
const fromPayload = linkFor({
|
|
type: "activity_published",
|
|
subjectId: null,
|
|
payloadVersion: 1,
|
|
payload: { activityId: "payload-id", activityName: "x", ownerUsername: "o", ownerDisplayName: null },
|
|
});
|
|
expect(fromPayload.web).toBe("/activities/payload-id");
|
|
});
|
|
|
|
it("activity_published falls back to / when both subjectId and payload are missing", () => {
|
|
const link = linkFor({
|
|
type: "activity_published",
|
|
subjectId: null,
|
|
payloadVersion: 1,
|
|
payload: null,
|
|
});
|
|
expect(link.web).toBe("/");
|
|
});
|
|
});
|