feat(housekeeping): deliver content vertical
This commit is contained in:
1 parent
bdab924bdf
commit
fd68819d9b
67 files changed
+5742
-1916
No files matched your search
@@ -0,0 +1,111 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { HousekeepingCapabilityContext } from "../../foundation/contracts";
|
||||
import { loadContentInboxItems } from "./inbox-production";
|
||||
import { loadContentSearchCandidates } from "./search-production";
|
||||
import { loadContentWidget } from "./widgets-production";
|
||||
|
||||
const { run } = vi.hoisted(() => ({ run: vi.fn() }));
|
||||
|
||||
vi.mock("./queries/content-queries", () => ({
|
||||
contentQuery: { run },
|
||||
}));
|
||||
|
||||
const context = {
|
||||
actor: { id: 42, username: "operator", rank: 7 },
|
||||
isSuperAdmin: false,
|
||||
has: () => true,
|
||||
hasAny: () => true,
|
||||
hasAll: () => true,
|
||||
} satisfies HousekeepingCapabilityContext;
|
||||
|
||||
function result(
|
||||
routeId: string,
|
||||
total: number,
|
||||
items: readonly Record<string, unknown>[] = [],
|
||||
) {
|
||||
return {
|
||||
ok: true as const,
|
||||
data: {
|
||||
kind: routeId.split(".")[1],
|
||||
items,
|
||||
total,
|
||||
partialDependencies: [],
|
||||
},
|
||||
correlationId: "provider-production",
|
||||
};
|
||||
}
|
||||
|
||||
describe("Content production providers", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
run.mockImplementation(async (_context, input) =>
|
||||
result(input.routeId, input.routeId.includes("articles") ? 7 : 3),
|
||||
);
|
||||
});
|
||||
|
||||
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("localization", context, signal),
|
||||
).resolves.toEqual({ stores: 3 });
|
||||
});
|
||||
|
||||
it("loads real search candidates from bounded query routes", async () => {
|
||||
run.mockImplementation(async (_context, input) =>
|
||||
result(input.routeId, 1, [
|
||||
{
|
||||
id: "9",
|
||||
title: "Launch",
|
||||
description: "Published",
|
||||
href: "/ase/content/editorial/articles/9",
|
||||
},
|
||||
]),
|
||||
);
|
||||
|
||||
const candidates = await loadContentSearchCandidates(
|
||||
"articles",
|
||||
context,
|
||||
"launch",
|
||||
25,
|
||||
);
|
||||
expect(candidates).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "content.editorial.articles:9",
|
||||
href: "/ase/content/editorial/articles/9",
|
||||
}),
|
||||
]);
|
||||
expect(run).toHaveBeenCalledWith(
|
||||
context,
|
||||
expect.objectContaining({ list: { search: "launch", pageSize: 25, offset: 0 } }),
|
||||
);
|
||||
});
|
||||
|
||||
it("builds publication inbox items only from real query rows", async () => {
|
||||
run.mockImplementation(async (_context, input) =>
|
||||
result(input.routeId, 1, [
|
||||
{
|
||||
id: "5",
|
||||
title: "Release",
|
||||
status: "published",
|
||||
updatedAt: new Date().toISOString(),
|
||||
href: "/ase/content/editorial/articles/5",
|
||||
},
|
||||
]),
|
||||
);
|
||||
|
||||
const items = await loadContentInboxItems(
|
||||
"publication",
|
||||
context,
|
||||
new AbortController().signal,
|
||||
);
|
||||
expect(items).toHaveLength(1);
|
||||
expect(items[0]).toMatchObject({
|
||||
itemId: "5",
|
||||
sourceId: "content.publication",
|
||||
href: "/ase/content/editorial/articles/5",
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user