fix: album assignment + approval error handling

Album assignment 500'd with IMMICH_UNAVAILABLE because grantAlbum verified the
album via getAlbum, which pulled the full album incl. all assets — large albums
blew the 15s timeout. Request ?withoutAssets=true so Immich returns metadata
only (no consumer reads .assets); make assets optional in the schema.

Album thumbnails 500'd because next/image rejected the ?albumId= query string
(images.localPatterns). Switch the album page to a plain <img>, matching the
editorial catalog (next/image was used in exactly one place).

Overhaul action error handling: grantAlbumAction/revokeAlbumAction/approveEditorialAction
returned a thrown Error, which Next.js turns into an opaque error-digest page —
the German message never reached the admin. They now return {ok,message}; new
client AlbumGrantForm + ApproveForm use useActionState to show the message
inline. Auth (requireAdmin) still throws (guarded by the layout). Update both
action test files to the result contract.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Leon TonhäuserandClaude committed 2026-08-11 02:09:16 +02:00
1 parent 7aeceee078
commit 089f5f7035
9 files changed
+233 -60

No files matched your search

+27 -9
View File
@@ -25,6 +25,8 @@ vi.mock("@/modules/editorials/service", () => ({
import { approveEditorialAction } from "./actions";
const initial = { ok: true, message: "" };
test("the approve action rejects unauthenticated callers before touching the service", async () => {
mocks.headers.mockResolvedValue(new Headers());
mocks.requireAdmin.mockRejectedValue(new Error("ADMIN_REQUIRED"));
@@ -32,7 +34,7 @@ test("the approve action rejects unauthenticated callers before touching the ser
formData.set("priceEuros", "10.00");
await expect(
approveEditorialAction("00000000-0000-4000-8000-000000000001", formData),
approveEditorialAction("00000000-0000-4000-8000-000000000001", initial, formData),
).rejects.toThrow("ADMIN_REQUIRED");
expect(mocks.approveEditorial).not.toHaveBeenCalled();
});
@@ -44,8 +46,13 @@ test("the approve action forwards the authenticated principal and cents price to
const formData = new FormData();
formData.set("priceEuros", "12,50");
await approveEditorialAction("00000000-0000-4000-8000-000000000001", formData);
const result = await approveEditorialAction(
"00000000-0000-4000-8000-000000000001",
initial,
formData,
);
expect(result).toEqual({ ok: true, message: "" });
expect(mocks.approveEditorial).toHaveBeenCalledWith({
editorialId: "00000000-0000-4000-8000-000000000001",
priceCents: 1250,
@@ -56,15 +63,19 @@ test("the approve action forwards the authenticated principal and cents price to
);
});
test("the approve action rejects a non-positive price before calling the service", async () => {
test("the approve action returns a German message for a non-positive price before calling the service", async () => {
mocks.headers.mockResolvedValue(new Headers());
mocks.requireAdmin.mockResolvedValue({ userId: "admin-1" });
const formData = new FormData();
formData.set("priceEuros", "0");
await expect(
approveEditorialAction("00000000-0000-4000-8000-000000000001", formData),
).rejects.toThrow("Bitte geben Sie einen gültigen Nettopreis an.");
const result = await approveEditorialAction(
"00000000-0000-4000-8000-000000000001",
initial,
formData,
);
expect(result).toEqual({ ok: false, message: "Bitte geben Sie einen gültigen Nettopreis an." });
expect(mocks.approveEditorial).not.toHaveBeenCalled();
});
@@ -76,7 +87,14 @@ test("the approve action translates a service error into a German message", asyn
const formData = new FormData();
formData.set("priceEuros", "10.00");
await expect(
approveEditorialAction("00000000-0000-4000-8000-000000000001", formData),
).rejects.toThrow("Bitte weisen Sie zuerst mindestens ein Album zu.");
const result = await approveEditorialAction(
"00000000-0000-4000-8000-000000000001",
initial,
formData,
);
expect(result).toEqual({
ok: false,
message: "Bitte weisen Sie zuerst mindestens ein Album zu.",
});
});