Show the Profile empty state, phone layout, and Rules you belong to.
This commit is contained in:
1 parent
b1ae274ff6
commit
c332b26683
4 files changed
+383
-138
No files matched your search
@@ -3,6 +3,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
const isDatabaseConfiguredMock = vi.fn();
|
||||
const findUniqueMock = vi.fn();
|
||||
const findManyMock = vi.fn();
|
||||
const stakeholderFindManyMock = vi.fn();
|
||||
const browserHoldsClaimForHashMock = vi.fn();
|
||||
const isRuleAdminEmailMock = vi.fn();
|
||||
const logAdminRuleReadMock = vi.fn();
|
||||
@@ -17,6 +18,9 @@ vi.mock("../../lib/server/db", () => ({
|
||||
findUnique: (...args: unknown[]) => findUniqueMock(...args),
|
||||
findMany: (...args: unknown[]) => findManyMock(...args),
|
||||
},
|
||||
ruleStakeholder: {
|
||||
findMany: (...args: unknown[]) => stakeholderFindManyMock(...args),
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -37,6 +41,7 @@ import {
|
||||
getReadablePublishedRule,
|
||||
listListedPublishedRules,
|
||||
listListedPublishedRulesForSitemap,
|
||||
listProfileRulesForUser,
|
||||
} from "../../lib/server/publishedRules";
|
||||
import { LISTED_PUBLISHED_RULE_WHERE } from "../../lib/publishedRuleAccess";
|
||||
import { RULE_VISIBILITY } from "../../lib/ruleVisibility";
|
||||
@@ -62,6 +67,7 @@ beforeEach(() => {
|
||||
isDatabaseConfiguredMock.mockReset();
|
||||
findUniqueMock.mockReset();
|
||||
findManyMock.mockReset();
|
||||
stakeholderFindManyMock.mockReset();
|
||||
browserHoldsClaimForHashMock.mockReset();
|
||||
isRuleAdminEmailMock.mockReset();
|
||||
logAdminRuleReadMock.mockReset();
|
||||
@@ -256,3 +262,60 @@ describe("listListedPublishedRulesForSitemap", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("listProfileRulesForUser", () => {
|
||||
it("returns null when the database is not configured", async () => {
|
||||
isDatabaseConfiguredMock.mockReturnValue(false);
|
||||
expect(await listProfileRulesForUser("user-1", 50)).toBeNull();
|
||||
expect(findManyMock).not.toHaveBeenCalled();
|
||||
expect(stakeholderFindManyMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("keeps owned Rules as owner and invited Rules as stakeholder, newest first", async () => {
|
||||
isDatabaseConfiguredMock.mockReturnValue(true);
|
||||
const owned = {
|
||||
id: "owned-1",
|
||||
title: "Garden coop",
|
||||
summary: "Plots",
|
||||
createdAt: new Date("2026-10-01T00:00:00.000Z"),
|
||||
updatedAt: new Date("2026-11-01T00:00:00.000Z"),
|
||||
};
|
||||
const invited = {
|
||||
id: "invited-1",
|
||||
title: "Hawthorn Row",
|
||||
summary: "Seeds",
|
||||
createdAt: new Date("2026-09-01T00:00:00.000Z"),
|
||||
updatedAt: new Date("2026-11-02T00:00:00.000Z"),
|
||||
};
|
||||
findManyMock.mockResolvedValueOnce([owned]);
|
||||
stakeholderFindManyMock.mockResolvedValueOnce([{ rule: invited }]);
|
||||
|
||||
const listed = await listProfileRulesForUser("user-1", 50);
|
||||
|
||||
expect(stakeholderFindManyMock).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
where: { userId: "user-1" },
|
||||
}),
|
||||
);
|
||||
expect(listed).toEqual([
|
||||
{ ...invited, role: "stakeholder" },
|
||||
{ ...owned, role: "owner" },
|
||||
]);
|
||||
});
|
||||
|
||||
it("does not list an invited Rule the person also holds the pen for as stakeholder", async () => {
|
||||
isDatabaseConfiguredMock.mockReturnValue(true);
|
||||
const owned = {
|
||||
id: "same-1",
|
||||
title: "Garden coop",
|
||||
summary: "Plots",
|
||||
createdAt: new Date("2026-10-01T00:00:00.000Z"),
|
||||
updatedAt: new Date("2026-11-01T00:00:00.000Z"),
|
||||
};
|
||||
findManyMock.mockResolvedValueOnce([owned]);
|
||||
stakeholderFindManyMock.mockResolvedValueOnce([{ rule: owned }]);
|
||||
|
||||
const listed = await listProfileRulesForUser("user-1", 50);
|
||||
expect(listed).toEqual([{ ...owned, role: "owner" }]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user