Manage stakeholders implemented

This commit is contained in:
adilallo
2026-05-09 23:07:59 -06:00
parent 534c6c7c0e
commit 9f2141a62d
43 changed files with 2082 additions and 93 deletions
+10 -7
View File
@@ -2,7 +2,7 @@ import { NextRequest } from "next/server";
import { beforeEach, describe, expect, it, vi } from "vitest";
const isDatabaseConfiguredMock = vi.fn();
const listForUserMock = vi.fn();
const listProfileMock = vi.fn();
const getSessionUserMock = vi.fn();
vi.mock("../../lib/server/env", () => ({
@@ -10,7 +10,7 @@ vi.mock("../../lib/server/env", () => ({
}));
vi.mock("../../lib/server/publishedRules", () => ({
listPublishedRulesForUser: (...args: unknown[]) => listForUserMock(...args),
listProfileRulesForUser: (...args: unknown[]) => listProfileMock(...args),
}));
vi.mock("../../lib/server/session", () => ({
@@ -21,7 +21,7 @@ import { GET } from "../../app/api/rules/me/route";
beforeEach(() => {
isDatabaseConfiguredMock.mockReset();
listForUserMock.mockReset();
listProfileMock.mockReset();
getSessionUserMock.mockReset();
});
@@ -44,7 +44,7 @@ describe("GET /api/rules/me", () => {
undefined,
);
expect(res.status).toBe(401);
expect(listForUserMock).not.toHaveBeenCalled();
expect(listProfileMock).not.toHaveBeenCalled();
});
it("returns 200 with { rules } for the session user", async () => {
@@ -59,17 +59,20 @@ describe("GET /api/rules/me", () => {
updatedAt: new Date("2026-01-02T00:00:00Z"),
},
];
listForUserMock.mockResolvedValueOnce(rows);
listProfileMock.mockResolvedValueOnce(
rows.map((r) => ({ ...r, role: "owner" as const })),
);
const res = await GET(
new NextRequest("https://x.test/api/rules/me?limit=10"),
undefined,
);
expect(res.status).toBe(200);
expect(listForUserMock).toHaveBeenCalledWith("user-1", 10);
expect(listProfileMock).toHaveBeenCalledWith("user-1", 10);
const body = (await res.json()) as {
rules: Array<{ id: string; title: string }>;
rules: Array<{ id: string; title: string; role: string }>;
};
expect(body.rules).toHaveLength(1);
expect(body.rules[0].id).toBe("r1");
expect(body.rules[0].role).toBe("owner");
});
});