fix(housekeeping): address task 14 review round 1

This commit is contained in:
Simo committed 2026-08-30 10:53:50 +02:00
1 parent fd68819d9b
commit d09eaa33d6
23 files changed
+2503 -488

No files matched your search

@@ -1,4 +1,5 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { PERMS } from "@/lib/permission-slugs";
import type { HousekeepingCapabilityContext } from "../../foundation/contracts";
import { loadContentInboxItems } from "./inbox-production";
import { loadContentSearchCandidates } from "./search-production";
@@ -18,6 +19,16 @@ const context = {
hasAll: () => true,
} satisfies HousekeepingCapabilityContext;
function capability(granted: readonly string[]): HousekeepingCapabilityContext {
const permissions = new Set(granted);
return {
...context,
has: (slug) => permissions.has(slug),
hasAny: (...slugs) => slugs.some((slug) => permissions.has(slug)),
hasAll: (...slugs) => slugs.every((slug) => permissions.has(slug)),
};
}
function result(
routeId: string,
total: number,
@@ -45,9 +56,9 @@ describe("Content production providers", () => {
it("returns only truthful persisted counts from editorial and localization widgets", async () => {
const signal = new AbortController().signal;
await expect(loadContentWidget("editorial", context, signal)).resolves.toEqual(
{ articles: 7 },
);
await expect(
loadContentWidget("editorial", context, signal),
).resolves.toEqual({ articles: 7 });
await expect(
loadContentWidget("localization", context, signal),
).resolves.toEqual({ stores: 3 });
@@ -79,7 +90,9 @@ describe("Content production providers", () => {
]);
expect(run).toHaveBeenCalledWith(
context,
expect.objectContaining({ list: { search: "launch", pageSize: 25, offset: 0 } }),
expect.objectContaining({
list: { search: "launch", pageSize: 25, offset: 0 },
}),
);
});
@@ -101,11 +114,59 @@ describe("Content production providers", () => {
context,
new AbortController().signal,
);
expect(items).toHaveLength(1);
expect(items[0]).toMatchObject({
itemId: "5",
sourceId: "content.publication",
href: "/ase/content/editorial/articles/5",
expect(items).toEqual([]);
});
it("loads only capability-matched media counts", async () => {
const result = await loadContentWidget(
"media",
capability([PERMS.BANNERS_VIEW]),
new AbortController().signal,
);
expect(result).toEqual({ banners: 3 });
expect(run).toHaveBeenCalledTimes(1);
expect(run).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({ routeId: "content.media.banners" }),
);
});
it("does not invent a zero when a widget dependency is unavailable", async () => {
run.mockResolvedValueOnce({
ok: false,
error: { code: "DEPENDENCY_UNAVAILABLE", messageKey: "dependency" },
correlationId: "unavailable",
});
await expect(
loadContentWidget("editorial", context, new AbortController().signal),
).rejects.toThrow("Content widget query unavailable");
});
it("emits only actionable publication statuses", async () => {
run.mockResolvedValueOnce(
result("content.editorial.articles", 2, [
{
id: "draft",
title: "Draft",
status: "draft",
updatedAt: new Date().toISOString(),
href: "/ase/content/editorial/articles/draft",
},
{
id: "published",
title: "Published",
status: "published",
updatedAt: new Date().toISOString(),
href: "/ase/content/editorial/articles/published",
},
]),
);
const items = await loadContentInboxItems(
"publication",
context,
new AbortController().signal,
);
expect(items.map((item) => item.itemId)).toEqual(["draft"]);
expect(items[0]?.state).toBe("draft");
});
});