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
+317
-72
No files matched your search
@@ -2,11 +2,11 @@
|
||||
|
||||
import { useId, useMemo } from "react";
|
||||
import Button from "../../../components/buttons/Button";
|
||||
import NoRules from "../../../components/cards/NoRules";
|
||||
import Rule from "../../../components/cards/Rule";
|
||||
import TextInput from "../../../components/controls/TextInput";
|
||||
import List from "../../../components/layout/List";
|
||||
import type { ListItem, ListSize } from "../../../components/layout/List";
|
||||
import ListEntry from "../../../components/layout/ListEntry";
|
||||
import Icon from "../../../components/asset/icon";
|
||||
import Dialog from "../../../components/modals/Dialog";
|
||||
import DeleteAccount from "../../../components/modals/DeleteAccount";
|
||||
@@ -29,6 +29,14 @@ function draftBodyTextFromState(
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function communityInitialsFromTitle(title: string): string {
|
||||
return title.trim().charAt(0).toUpperCase() || "·";
|
||||
}
|
||||
|
||||
function fillName(template: string, name: string): string {
|
||||
return template.replace(/\{\{name\}\}/g, name);
|
||||
}
|
||||
|
||||
export type ProfilePageViewProps = {
|
||||
userEmail: string;
|
||||
/** `M` below `lg` (1024px); `L` at `lg`+ per Figma Card / Rule. Breakpoints: `md` (640px) → `lg` (1024px) only. */
|
||||
@@ -107,7 +115,7 @@ export function ProfilePageSignedOutView({
|
||||
|
||||
return (
|
||||
<div className="w-full bg-[var(--color-surface-default-primary)] text-[var(--color-content-default-primary)]">
|
||||
<div className="flex flex-col gap-6 px-4 pt-4 pb-4 md:px-8 lg:gap-10 lg:px-16">
|
||||
<div className="flex flex-col gap-8 px-5 pt-2 pb-8 md:px-8 lg:gap-10 lg:px-16">
|
||||
<header
|
||||
className={
|
||||
profileLgUp
|
||||
@@ -153,9 +161,9 @@ export function ProfilePageSignedOutView({
|
||||
}
|
||||
|
||||
/**
|
||||
* Figma: mobile `22143:900762`; tablet `md` `22143:900534` (`@theme --breakpoint-md` 640px);
|
||||
* desktop `lg` `21962:17220` (`@theme --breakpoint-lg` 1024px);
|
||||
* `xl` `22143:900247` (same content spacing as lg; list + section type at `xl` — `List` L `21844:4405`).
|
||||
* Figma: phone `25032:88248` / empty `25032:88410` (320–639);
|
||||
* several Rules `25206:93086`; belong-to phone `25219:136704` and desktop `25219:136446`;
|
||||
* desktop empty `25032:88574`; `xl` list + section type `22143:900247` (`List` L `21844:4405`).
|
||||
*/
|
||||
export function ProfilePageView({
|
||||
userEmail,
|
||||
@@ -207,9 +215,27 @@ export function ProfilePageView({
|
||||
const t = useTranslation("pages.profile");
|
||||
const tLogin = useTranslation("pages.login");
|
||||
const titleId = useId();
|
||||
const welcomeTitle = t("welcomeTitle").replace(/\{\{name\}\}/g, userEmail);
|
||||
const welcomeBody =
|
||||
rules.length > 0 ? t("welcomeBodyFirstRule") : t("welcomeBodyNoRules");
|
||||
const ownedRules = useMemo(
|
||||
() => rules.filter((rule) => rule.role === "owner"),
|
||||
[rules],
|
||||
);
|
||||
const belongToRules = useMemo(
|
||||
() => rules.filter((rule) => rule.role === "stakeholder"),
|
||||
[rules],
|
||||
);
|
||||
const welcomeTitle = fillName(
|
||||
showDraftCard || ownedRules.length === 0
|
||||
? t("welcomeTitleReturn")
|
||||
: t("welcomeTitle"),
|
||||
userEmail,
|
||||
);
|
||||
const welcomeBody = showDraftCard
|
||||
? t("welcomeBodyReturn")
|
||||
: ownedRules.length > 0
|
||||
? t("welcomeBodyFirstRule")
|
||||
: undefined;
|
||||
const showEmptyYourRules =
|
||||
ownedRules.length === 0 && !showDraftCard && !rulesError;
|
||||
|
||||
const profileOptionsItems = useMemo((): ListItem[] => {
|
||||
return [
|
||||
@@ -245,16 +271,32 @@ export function ProfilePageView({
|
||||
leadingIcon: "mail",
|
||||
showDescription: false,
|
||||
},
|
||||
{
|
||||
id: "delete-account",
|
||||
title: t("deleteAccount"),
|
||||
description: "",
|
||||
onClick: onOpenDeleteAccount,
|
||||
leadingIcon: "warning",
|
||||
variant: "danger",
|
||||
showDescription: false,
|
||||
},
|
||||
];
|
||||
}, [t, onSignOut, onOpenEmailChange, onStartNewCustomRule]);
|
||||
}, [
|
||||
t,
|
||||
onSignOut,
|
||||
onOpenEmailChange,
|
||||
onOpenDeleteAccount,
|
||||
onStartNewCustomRule,
|
||||
]);
|
||||
|
||||
const ruleCardShellClass =
|
||||
"w-full !max-w-full cursor-default !gap-3 !rounded-[12px] shadow-[0_0_48px_rgba(0,0,0,0.1)] lg:!rounded-[24px] lg:shadow-[0_0_24px_rgba(0,0,0,0.1)]";
|
||||
"w-full !max-w-full !gap-3 !rounded-[12px] shadow-[0_0_48px_rgba(0,0,0,0.1)] lg:!rounded-[24px] lg:shadow-[0_0_24px_rgba(0,0,0,0.1)]";
|
||||
const ownedRuleCardShellClass = `${ruleCardShellClass} cursor-default`;
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="w-full bg-[var(--color-surface-default-primary)] text-[var(--color-content-default-primary)]">
|
||||
<div className="flex flex-col gap-6 px-4 pt-4 pb-4 md:px-8 lg:gap-10 lg:px-16">
|
||||
<div className="flex flex-col gap-8 px-5 pt-2 pb-8 md:px-8 lg:gap-10 lg:px-16">
|
||||
<header
|
||||
className={
|
||||
profileLgUp
|
||||
@@ -278,16 +320,19 @@ export function ProfilePageView({
|
||||
>
|
||||
{welcomeTitle}
|
||||
</h1>
|
||||
{welcomeBody ? (
|
||||
<p className="max-w-[640px] text-small-paragraph text-[var(--color-content-default-tertiary)] md:text-medium-paragraph">
|
||||
{welcomeBody}
|
||||
</p>
|
||||
) : null}
|
||||
</>
|
||||
)}
|
||||
</header>
|
||||
|
||||
<div className="flex flex-col gap-8 lg:flex-row lg:flex-nowrap lg:items-start lg:gap-8">
|
||||
<div className="flex flex-col gap-10 lg:flex-row lg:flex-nowrap lg:items-start lg:gap-8">
|
||||
<div className="flex min-w-0 w-full flex-col gap-10 lg:min-w-0 lg:flex-1">
|
||||
<section
|
||||
className="flex min-w-0 w-full flex-col gap-3 lg:min-w-0 lg:flex-1 lg:gap-6"
|
||||
className="flex min-w-0 w-full flex-col gap-4 lg:gap-6"
|
||||
aria-labelledby="profile-rules-heading"
|
||||
>
|
||||
<h2
|
||||
@@ -297,6 +342,16 @@ export function ProfilePageView({
|
||||
>
|
||||
{t("yourRulesHeading")}
|
||||
</h2>
|
||||
{showEmptyYourRules ? (
|
||||
<NoRules
|
||||
title={t("emptyCardTitle")}
|
||||
description={t("emptyCardBody")}
|
||||
createLabel={t("emptyCardCreate")}
|
||||
browseLabel={t("emptyCardBrowse")}
|
||||
onCreate={onStartNewCustomRule}
|
||||
browseHref="/templates?fromFlow=1"
|
||||
/>
|
||||
) : (
|
||||
<div className="flex flex-col gap-3">
|
||||
{showDraftCard && draft?.hasDraft ? (
|
||||
<Rule
|
||||
@@ -322,16 +377,16 @@ export function ProfilePageView({
|
||||
onClick: onDeleteDraft,
|
||||
},
|
||||
]}
|
||||
communityInitials={(() => {
|
||||
const raw = draft.state.title;
|
||||
const s = typeof raw === "string" ? raw.trim() : "";
|
||||
return s.charAt(0).toUpperCase() || "·";
|
||||
})()}
|
||||
communityInitials={communityInitialsFromTitle(
|
||||
typeof draft.state.title === "string"
|
||||
? draft.state.title
|
||||
: "",
|
||||
)}
|
||||
backgroundColor="bg-[var(--color-surface-invert-brand-teal)]"
|
||||
className={ruleCardShellClass}
|
||||
className={ownedRuleCardShellClass}
|
||||
/>
|
||||
) : null}
|
||||
{rules.map((rule) => (
|
||||
{ownedRules.map((rule) => (
|
||||
<Rule
|
||||
key={rule.id}
|
||||
title={rule.title}
|
||||
@@ -339,21 +394,8 @@ export function ProfilePageView({
|
||||
expanded
|
||||
size={ruleCardSize}
|
||||
hasBottomLinks
|
||||
bottomStatusLabel={
|
||||
rule.role === "stakeholder"
|
||||
? undefined
|
||||
: t("finishedBadge")
|
||||
}
|
||||
bottomLinks={
|
||||
rule.role === "stakeholder"
|
||||
? [
|
||||
{
|
||||
id: "view",
|
||||
label: t("viewPublic"),
|
||||
href: `/invite/${encodeURIComponent(rule.id)}`,
|
||||
},
|
||||
]
|
||||
: [
|
||||
bottomStatusLabel={t("finishedBadge")}
|
||||
bottomLinks={[
|
||||
{
|
||||
id: "invite",
|
||||
label: t("inviteMembers"),
|
||||
@@ -369,25 +411,53 @@ export function ProfilePageView({
|
||||
label: t("deleteRule"),
|
||||
onClick: () => onDeleteRule(rule.id),
|
||||
},
|
||||
]
|
||||
}
|
||||
communityInitials={
|
||||
rule.title.trim().charAt(0).toUpperCase() || "·"
|
||||
}
|
||||
]}
|
||||
communityInitials={communityInitialsFromTitle(
|
||||
rule.title,
|
||||
)}
|
||||
backgroundColor="bg-[var(--color-surface-invert-brand-teal)]"
|
||||
className={ownedRuleCardShellClass}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
{belongToRules.length > 0 ? (
|
||||
<section
|
||||
className="flex min-w-0 w-full flex-col gap-4 lg:gap-6"
|
||||
aria-labelledby="profile-belong-to-heading"
|
||||
>
|
||||
<h2
|
||||
id="profile-belong-to-heading"
|
||||
className={profileSectionHeadingClass}
|
||||
style={{ fontVariationSettings: "'opsz' 14, 'wdth' 100" }}
|
||||
>
|
||||
{t("rulesYouBelongToHeading")}
|
||||
</h2>
|
||||
<div className="flex flex-col gap-3">
|
||||
{belongToRules.map((rule) => (
|
||||
<Rule
|
||||
key={rule.id}
|
||||
title={rule.title}
|
||||
description={rule.summary ?? undefined}
|
||||
expanded
|
||||
size={ruleCardSize}
|
||||
href={`/invite/${encodeURIComponent(rule.id)}`}
|
||||
communityInitials={communityInitialsFromTitle(
|
||||
rule.title,
|
||||
)}
|
||||
backgroundColor="bg-[var(--color-surface-invert-brand-kiwi)]"
|
||||
className={ruleCardShellClass}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
{rules.length === 0 && !rulesError && !showDraftCard ? (
|
||||
<p className="text-small-paragraph text-[var(--color-content-default-tertiary)]">
|
||||
{t("yourRulesEmpty")}
|
||||
</p>
|
||||
) : null}
|
||||
</section>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<section
|
||||
className="flex min-w-0 w-full flex-col gap-3 lg:min-w-0 lg:flex-1 lg:gap-6"
|
||||
className="flex min-w-0 w-full flex-col gap-4 lg:min-w-0 lg:flex-1 lg:gap-6"
|
||||
aria-labelledby="profile-options-heading"
|
||||
>
|
||||
<h2
|
||||
@@ -405,22 +475,6 @@ export function ProfilePageView({
|
||||
leadingIcon="edit"
|
||||
/>
|
||||
</nav>
|
||||
<section
|
||||
aria-label={t("deleteAccount")}
|
||||
className="w-full overflow-hidden rounded-[12px] border border-[var(--color-border-default-negative-primary)] bg-[var(--color-surface-default-negative-secondary)]"
|
||||
>
|
||||
<ListEntry
|
||||
title={t("deleteAccount")}
|
||||
description=""
|
||||
showDescription={false}
|
||||
onClick={onOpenDeleteAccount}
|
||||
size={profileListSize}
|
||||
leadingIcon="edit"
|
||||
variant="danger"
|
||||
topDivider={false}
|
||||
bottomDivider={false}
|
||||
/>
|
||||
</section>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
{
|
||||
"pageTitle": "Your profile",
|
||||
"welcomeTitle": "Congrats {{name}}!",
|
||||
"welcomeTitle": "Congrats, {{name}}",
|
||||
"welcomeTitleReturn": "Welcome back, {{name}}",
|
||||
"welcomeBodyFirstRule": "Invite the people in your community to read it.",
|
||||
"welcomeBodyReturn": "Pick up where you left off or start a new Rule.",
|
||||
"welcomeBodyNoRules": "Create your first CommunityRule to capture how your group makes decisions—then link it from your community resources as you grow.",
|
||||
"yourOptionsHeading": "Your options",
|
||||
"optionCreateCustom": "Create new custom Rule",
|
||||
@@ -13,7 +15,12 @@
|
||||
"signInCta": "Log in",
|
||||
"loading": "Loading…",
|
||||
"yourRulesHeading": "Your Rules",
|
||||
"rulesYouBelongToHeading": "Rules you belong to",
|
||||
"yourRulesEmpty": "You have not finished a rule yet. Create one to see it here.",
|
||||
"emptyCardTitle": "No Rules yet",
|
||||
"emptyCardBody": "Start from a template, or write your first over a few short meetings with the free kit.",
|
||||
"emptyCardCreate": "Create rule",
|
||||
"emptyCardBrowse": "Browse templates",
|
||||
"draftHeading": "Saved in progress",
|
||||
"draftInProgressBadge": "Draft",
|
||||
"finishedBadge": "Finished",
|
||||
|
||||
@@ -72,7 +72,7 @@ function viewProps(
|
||||
}
|
||||
|
||||
describe("ProfilePageView", () => {
|
||||
test("puts delete account in its own danger area", () => {
|
||||
test("puts delete account in the options list as a danger row", () => {
|
||||
render(<ProfilePageView {...viewProps()} />);
|
||||
|
||||
const options = screen.getByRole("navigation", {
|
||||
@@ -81,16 +81,12 @@ describe("ProfilePageView", () => {
|
||||
expect(
|
||||
within(options).getByRole("button", { name: copy.optionCreateCustom }),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
within(options).queryByRole("button", { name: copy.deleteAccount }),
|
||||
).not.toBeInTheDocument();
|
||||
expect(screen.queryByText(copy.deleteAccountIntro)).not.toBeInTheDocument();
|
||||
expect(
|
||||
screen.queryByRole("region", { name: copy.deleteAccount }),
|
||||
).not.toBeInTheDocument();
|
||||
|
||||
const danger = screen.getByRole("region", { name: copy.deleteAccount });
|
||||
expect(danger.className).toContain(
|
||||
"border-[var(--color-border-default-negative-primary)]",
|
||||
);
|
||||
const deleteAccount = within(danger).getByRole("button", {
|
||||
const deleteAccount = within(options).getByRole("button", {
|
||||
name: copy.deleteAccount,
|
||||
});
|
||||
const deleteTitle = within(deleteAccount).getByText(copy.deleteAccount);
|
||||
@@ -105,6 +101,33 @@ describe("ProfilePageView", () => {
|
||||
);
|
||||
});
|
||||
|
||||
test("shows the No Rules card when the person has no owned Rule", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onStartNewCustomRule = vi.fn();
|
||||
render(
|
||||
<ProfilePageView {...viewProps({ onStartNewCustomRule })} />,
|
||||
);
|
||||
|
||||
expect(
|
||||
screen.getByRole("heading", {
|
||||
name: copy.welcomeTitleReturn.replace("{{name}}", "dani@example.com"),
|
||||
}),
|
||||
).toBeInTheDocument();
|
||||
expect(screen.queryByText(copy.welcomeBodyFirstRule)).not.toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole("heading", { name: copy.emptyCardTitle }),
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByText(copy.emptyCardBody)).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole("link", { name: copy.emptyCardBrowse }),
|
||||
).toHaveAttribute("href", "/templates?fromFlow=1");
|
||||
|
||||
await user.click(
|
||||
screen.getByRole("button", { name: copy.emptyCardCreate }),
|
||||
);
|
||||
expect(onStartNewCustomRule).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test("asks for confirmation before deleting the account", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onOpenDeleteAccount = vi.fn();
|
||||
@@ -193,4 +216,102 @@ describe("ProfilePageView", () => {
|
||||
screen.getByRole("button", { name: copy.deleteRule }),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("lists invited Rules under Rules you belong to, not Your Rules", () => {
|
||||
render(
|
||||
<ProfilePageView
|
||||
{...viewProps({
|
||||
rules: [
|
||||
{
|
||||
id: "rule-owned",
|
||||
title: "Garden coop",
|
||||
summary: "How we share the plots.",
|
||||
createdAt: "2026-11-01T00:00:00.000Z",
|
||||
updatedAt: "2026-11-01T00:00:00.000Z",
|
||||
role: "owner",
|
||||
},
|
||||
{
|
||||
id: "rule-invited",
|
||||
title: "Hawthorn Row Seed Library",
|
||||
summary: "Neighbors save seeds each fall.",
|
||||
createdAt: "2026-10-01T00:00:00.000Z",
|
||||
updatedAt: "2026-10-01T00:00:00.000Z",
|
||||
role: "stakeholder",
|
||||
},
|
||||
],
|
||||
})}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(
|
||||
screen.getByRole("heading", { name: copy.rulesYouBelongToHeading }),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole("link", { name: /Hawthorn Row Seed Library/ }),
|
||||
).toHaveAttribute("href", "/invite/rule-invited");
|
||||
expect(
|
||||
screen.queryByRole("button", { name: copy.viewPublic }),
|
||||
).not.toBeInTheDocument();
|
||||
|
||||
const yourRules = screen.getByRole("region", {
|
||||
name: copy.yourRulesHeading,
|
||||
});
|
||||
expect(within(yourRules).getByText("Garden coop")).toBeInTheDocument();
|
||||
expect(
|
||||
within(yourRules).queryByText("Hawthorn Row Seed Library"),
|
||||
).not.toBeInTheDocument();
|
||||
expect(
|
||||
within(yourRules).getByRole("button", { name: copy.inviteMembers }),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("hides Rules you belong to when nothing was shared with this address", () => {
|
||||
render(
|
||||
<ProfilePageView
|
||||
{...viewProps({
|
||||
rules: [
|
||||
{
|
||||
id: "rule-1",
|
||||
title: "Garden coop",
|
||||
summary: "How we share the plots.",
|
||||
createdAt: "2026-11-01T00:00:00.000Z",
|
||||
updatedAt: "2026-11-01T00:00:00.000Z",
|
||||
role: "owner",
|
||||
},
|
||||
],
|
||||
})}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(
|
||||
screen.queryByRole("heading", { name: copy.rulesYouBelongToHeading }),
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("uses the return-visit greeting when a draft is in progress", () => {
|
||||
render(
|
||||
<ProfilePageView
|
||||
{...viewProps({
|
||||
showDraftCard: true,
|
||||
draft: {
|
||||
hasDraft: true,
|
||||
updatedAt: "2026-11-01T00:00:00.000Z",
|
||||
state: { title: "Alder Court Tenants Union" },
|
||||
} as ProfilePageViewProps["draft"],
|
||||
})}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(
|
||||
screen.getByRole("heading", {
|
||||
name: copy.welcomeTitleReturn.replace("{{name}}", "dani@example.com"),
|
||||
}),
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByText(copy.welcomeBodyReturn)).toBeInTheDocument();
|
||||
expect(screen.getByText("Alder Court Tenants Union")).toBeInTheDocument();
|
||||
expect(screen.getByText(copy.draftInProgressBadge)).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole("button", { name: copy.continueDraft }),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -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