Keep listed published rules public and guest-claim rules unlisted, with semantic document markup and share chrome that stays clickable.

Guest publishes remain share-by-link but stay out of the catalog and sitemap, and their pages send noindex until claimed. The published-rule view now uses heading and list markup matching Markdown export, and top banners sit below the header so Share is not covered.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
adilalloandCursor committed 2026-09-17 17:42:01 -06:00
1 parent 77b0ec8ad8
commit 1445cb7e1e
27 files changed
+524 -86

No files matched your search

+31 -13
View File
@@ -2,16 +2,21 @@ import { NextRequest } from "next/server";
import { beforeEach, describe, expect, it, vi } from "vitest";
const isDatabaseConfiguredMock = vi.fn();
const findManyMock = vi.fn();
const listListedMock = vi.fn();
vi.mock("../../lib/server/env", () => ({
isDatabaseConfigured: () => isDatabaseConfiguredMock(),
}));
vi.mock("../../lib/server/publishedRules", () => ({
listListedPublishedRules: (...args: unknown[]) => listListedMock(...args),
}));
vi.mock("../../lib/server/db", () => ({
prisma: {
publishedRule: {
findMany: (...args: unknown[]) => findManyMock(...args),
findMany: vi.fn(),
create: vi.fn(),
},
},
}));
@@ -20,7 +25,7 @@ import { GET } from "../../app/api/rules/route";
beforeEach(() => {
isDatabaseConfiguredMock.mockReset();
findManyMock.mockReset();
listListedMock.mockReset();
});
describe("GET /api/rules", () => {
@@ -31,12 +36,12 @@ describe("GET /api/rules", () => {
undefined,
);
expect(res.status).toBe(503);
expect(findManyMock).not.toHaveBeenCalled();
expect(listListedMock).not.toHaveBeenCalled();
});
it("lists owned rules only", async () => {
it("lists listed rules from the shared helper", async () => {
isDatabaseConfiguredMock.mockReturnValue(true);
findManyMock.mockResolvedValueOnce([
listListedMock.mockResolvedValueOnce([
{
id: "r1",
title: "Owned",
@@ -52,13 +57,26 @@ describe("GET /api/rules", () => {
);
expect(res.status).toBe(200);
expect(findManyMock).toHaveBeenCalledWith(
expect.objectContaining({
where: { userId: { not: null } },
take: 10,
}),
);
expect(listListedMock).toHaveBeenCalledWith(10);
const body = (await res.json()) as { rules: Array<{ id: string }> };
expect(body.rules).toEqual([{ id: "r1", title: "Owned", summary: null, createdAt: expect.any(String), updatedAt: expect.any(String) }]);
expect(body.rules).toEqual([
{
id: "r1",
title: "Owned",
summary: null,
createdAt: expect.any(String),
updatedAt: expect.any(String),
},
]);
});
it("returns 500 when the list helper fails", async () => {
isDatabaseConfiguredMock.mockReturnValue(true);
listListedMock.mockResolvedValueOnce(null);
const res = await GET(
new NextRequest("https://x.test/api/rules"),
undefined,
);
expect(res.status).toBe(500);
});
});