fix(housekeeping): complete people workflow fidelity

This commit is contained in:
Simo committed 2026-08-29 14:39:38 +02:00
1 parent 25b76437ff
commit 91c9efcbb4
29 files changed
+1365 -290

No files matched your search

@@ -1,6 +1,7 @@
import { readFileSync } from "node:fs";
import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it, vi } from "vitest";
import { executeHousekeepingCommand } from "@/actions/housekeeping-command";
import { PERMS } from "@/lib/permission-slugs";
vi.mock("@/actions/housekeeping-command", () => ({
@@ -26,6 +27,10 @@ import {
import { PeopleCommunityPage } from "./community";
import { PeopleMultiAccountsPage } from "./multi-accounts";
import { parsePeopleListInput } from "./page-state";
import {
PeopleCommandResult,
submitPeopleCommandForm,
} from "./people-command-form";
import { PeopleStaffPage } from "./staff";
import { PeopleUserDetailPage } from "./user-detail";
import { PeopleUserEditPage } from "./user-edit";
@@ -215,7 +220,7 @@ const cases: readonly PageCase[] = [
page: {
items: [
{
id: 5,
id: "5",
userId: 7,
username: "Alice",
rankId: 4,
@@ -342,17 +347,58 @@ describe("People URL list input", () => {
});
});
describe("People actionable form contract", () => {
it("submits bounded command input and reason through the existing server action", () => {
const source = readFileSync(
"src/features/housekeeping/domains/people/pages/people-command-form.tsx",
"utf8",
it("submits bounded command input and reason through the actual form action adapter", async () => {
vi.mocked(executeHousekeepingCommand).mockResolvedValue(
ok({ before: null, after: { amount: 100 } }, "form-action"),
);
expect(source).toContain("executeHousekeepingCommand({");
expect(source).toContain("commandId");
expect(source).toContain("input: commandInput");
expect(source).toContain("{ reason }");
expect(source).toContain("action={submit}");
expect(source).not.toContain("<span data-housekeeping-command");
const formData = new FormData();
formData.set("amount", "999");
formData.set("reason", " Planned grant ");
const result = await submitPeopleCommandForm(
{
commandId: "people.user.send-currency",
input: { userId: 7 },
fields: [
{
name: "amount",
label: "Amount",
type: "number",
min: 1,
max: 100,
},
],
requiresReason: true,
includeReasonInInput: true,
},
null,
formData,
);
expect(executeHousekeepingCommand).toHaveBeenCalledWith({
commandId: "people.user.send-currency",
input: { userId: 7, amount: 100, reason: "Planned grant" },
reason: "Planned grant",
});
expect(result).toMatchObject({ ok: true });
});
it("renders a generated reset credential once in the current accessible result", () => {
const password = "one-time-secret";
const html = renderToStaticMarkup(
<PeopleCommandResult
result={ok(
{
before: { passwordReset: false },
after: { passwordReset: true },
output: { newPassword: password },
},
"reset-result",
)}
/>,
);
expect(html).toContain('aria-label="Generated temporary password"');
expect(html.match(new RegExp(password, "gu"))).toHaveLength(1);
});
it("provides a real Next loading boundary", () => {