fix(housekeeping): address task 14 review round 3
This commit is contained in:
1 parent
c524b305d7
commit
d1160eb65a
7 files changed
+243
-40
No files matched your search
@@ -265,6 +265,45 @@ describe("Content legacy wrappers", () => {
|
||||
expect(auditedBrandExecute).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("maps a favicon audit partial to the truthful legacy result shape", async () => {
|
||||
auditedBrandExecute.mockResolvedValueOnce({
|
||||
before: { value: "/old.ico" },
|
||||
after: { value: "/api/media/favicon/new.ico" },
|
||||
output: { url: "/api/media/favicon/new.ico" },
|
||||
completion: {
|
||||
status: "partial",
|
||||
external: "completed",
|
||||
audit: "unavailable",
|
||||
},
|
||||
});
|
||||
const file = new File(["bytes"], "favicon.png", { type: "image/png" });
|
||||
await expect(saveFavicon(form({ file }) as FormData)).resolves.toEqual({
|
||||
success: false,
|
||||
url: "/api/media/favicon/new.ico",
|
||||
error:
|
||||
"Favicon change completed partially; verify storage and audit state",
|
||||
});
|
||||
});
|
||||
|
||||
it("maps a logo audit partial to the truthful legacy result shape", async () => {
|
||||
auditedBrandExecute.mockResolvedValueOnce({
|
||||
before: { value: "/old.png" },
|
||||
after: { value: "/api/media/logo/new.png" },
|
||||
output: { url: "/api/media/logo/new.png" },
|
||||
completion: {
|
||||
status: "partial",
|
||||
external: "completed",
|
||||
audit: "unavailable",
|
||||
},
|
||||
});
|
||||
const file = new File(["bytes"], "logo.png", { type: "image/png" });
|
||||
await expect(saveLogo(form({ file }) as FormData)).resolves.toEqual({
|
||||
success: false,
|
||||
url: "/api/media/logo/new.png",
|
||||
error: "Logo change completed partially; verify storage and audit state",
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps every listed legacy action as a thin shared-service wrapper", () => {
|
||||
for (const path of [
|
||||
"src/actions/admin-ads.ts",
|
||||
|
||||
@@ -15,6 +15,8 @@ const ALLOWED = [
|
||||
"image/x-icon",
|
||||
"image/svg+xml",
|
||||
];
|
||||
const PARTIAL_ERROR =
|
||||
"Favicon change completed partially; verify storage and audit state";
|
||||
|
||||
async function executeAuditedFaviconMutation(
|
||||
staff: StaffUser,
|
||||
@@ -59,11 +61,18 @@ export async function saveFavicon(
|
||||
file,
|
||||
});
|
||||
siteRevalidate();
|
||||
const url =
|
||||
typeof result.output?.url === "string" ? result.output.url : undefined;
|
||||
if (result.completion?.status === "partial") {
|
||||
return {
|
||||
success: false,
|
||||
...(url ? { url } : {}),
|
||||
error: PARTIAL_ERROR,
|
||||
};
|
||||
}
|
||||
return {
|
||||
success: true,
|
||||
...(typeof result.output?.url === "string"
|
||||
? { url: result.output.url }
|
||||
: {}),
|
||||
...(url ? { url } : {}),
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
@@ -79,8 +88,14 @@ export async function deleteFavicon(): Promise<{
|
||||
}> {
|
||||
const staff = await requirePermission(PERMS.SETTINGS_VIEW);
|
||||
try {
|
||||
await executeAuditedFaviconMutation(staff, "favicon.delete", {});
|
||||
const result = await executeAuditedFaviconMutation(
|
||||
staff,
|
||||
"favicon.delete",
|
||||
{},
|
||||
);
|
||||
siteRevalidate();
|
||||
if (result.completion?.status === "partial")
|
||||
return { success: false, error: PARTIAL_ERROR };
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
return {
|
||||
|
||||
@@ -5,6 +5,9 @@ import type { ContentMutationSnapshot } from "@/features/housekeeping/domains/co
|
||||
import { createCorrelationId } from "@/features/housekeeping/foundation/contracts";
|
||||
import { requireStaff, type StaffUser } from "@/lib/admin/guard";
|
||||
|
||||
const PARTIAL_ERROR =
|
||||
"Logo change completed partially; verify storage and audit state";
|
||||
|
||||
async function executeAuditedLogoMutation(
|
||||
staff: StaffUser,
|
||||
input: unknown,
|
||||
@@ -37,11 +40,18 @@ export async function saveLogo(
|
||||
if (!file) return { success: false, error: "No file provided" };
|
||||
const result = await executeAuditedLogoMutation(staff, { file });
|
||||
revalidatePath("/", "layout");
|
||||
const url =
|
||||
typeof result.output?.url === "string" ? result.output.url : undefined;
|
||||
if (result.completion?.status === "partial") {
|
||||
return {
|
||||
success: false,
|
||||
...(url ? { url } : {}),
|
||||
error: PARTIAL_ERROR,
|
||||
};
|
||||
}
|
||||
return {
|
||||
success: true,
|
||||
...(typeof result.output?.url === "string"
|
||||
? { url: result.output.url }
|
||||
: {}),
|
||||
...(url ? { url } : {}),
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user