diff --git a/src/app/admin/redaktionen/[id]/alben/page-content.ts b/src/app/admin/redaktionen/[id]/alben/page-content.ts new file mode 100644 index 0000000..a8eb8c9 --- /dev/null +++ b/src/app/admin/redaktionen/[id]/alben/page-content.ts @@ -0,0 +1,16 @@ +import { AlbumGrantError, albumGrantService } from "@/modules/albums/grants"; + +export async function loadAssignableAlbums( + editorialId: string, + service: Pick = albumGrantService, +) { + try { + const albums = await service.listAssignableAlbums(editorialId); + return { albums, unavailable: false }; + } catch (error) { + if (error instanceof AlbumGrantError && error.code === "IMMICH_UNAVAILABLE") { + return { albums: [], unavailable: true }; + } + throw error; + } +} diff --git a/src/app/admin/redaktionen/[id]/alben/page.test.tsx b/src/app/admin/redaktionen/[id]/alben/page.test.tsx new file mode 100644 index 0000000..abad4cd --- /dev/null +++ b/src/app/admin/redaktionen/[id]/alben/page.test.tsx @@ -0,0 +1,47 @@ +// @vitest-environment jsdom + +import { render, screen } from "@testing-library/react"; +import { expect, test, vi } from "vitest"; + +import { EditorialDetailContent } from "@/modules/editorials/admin-detail"; +import { AlbumGrantError } from "@/modules/albums/grants"; +import { loadAssignableAlbums } from "./page-content"; + +const editorial = { + id: "00000000-0000-4000-8000-000000000001", + name: "Neue Redaktion", + contactName: "Mara Muster", + loginEmail: "mara@example.com", + status: "pending_approval" as const, + emailVerifiedAt: null, + currentPriceCents: null, +}; + +test("the editorial detail links admins to its album-assignment page", () => { + render(); + + expect(screen.getByRole("link", { name: /albumrechte verwalten/i }).getAttribute("href")).toBe( + "/admin/redaktionen/00000000-0000-4000-8000-000000000001/alben", + ); + expect(screen.queryByText(/folgt im nächsten schritt/i)).toBeNull(); +}); + +test("only an explicit Immich-unavailable error renders the unavailable album state", async () => { + const service = { + listAssignableAlbums: vi.fn().mockRejectedValue(new AlbumGrantError("IMMICH_UNAVAILABLE")), + }; + + await expect(loadAssignableAlbums(editorial.id, service)).resolves.toEqual({ + albums: [], + unavailable: true, + }); +}); + +test("database and programming errors propagate instead of being displayed as Immich unavailable", async () => { + const databaseFailure = new Error("database connection lost"); + const service = { + listAssignableAlbums: vi.fn().mockRejectedValue(databaseFailure), + }; + + await expect(loadAssignableAlbums(editorial.id, service)).rejects.toBe(databaseFailure); +}); diff --git a/src/app/admin/redaktionen/[id]/alben/page.tsx b/src/app/admin/redaktionen/[id]/alben/page.tsx index 1083504..d1659d8 100644 --- a/src/app/admin/redaktionen/[id]/alben/page.tsx +++ b/src/app/admin/redaktionen/[id]/alben/page.tsx @@ -8,6 +8,7 @@ import { editorialAccounts } from "@/db/schema"; import { albumGrantService } from "@/modules/albums/grants"; import { grantAlbumAction, revokeAlbumAction } from "./actions"; +import { loadAssignableAlbums } from "./page-content"; export default async function EditorialAlbumsPage({ params, @@ -22,10 +23,7 @@ export default async function EditorialAlbumsPage({ notFound(); } - const albumResult = await albumGrantService - .listAssignableAlbums(editorial.id) - .then((albums) => ({ albums, unavailable: false })) - .catch(() => ({ albums: [], unavailable: true })); + const albumResult = await loadAssignableAlbums(editorial.id, albumGrantService); if (albumResult.unavailable) { return ( diff --git a/src/app/admin/redaktionen/[id]/page.tsx b/src/app/admin/redaktionen/[id]/page.tsx index dd2e7e0..5149293 100644 --- a/src/app/admin/redaktionen/[id]/page.tsx +++ b/src/app/admin/redaktionen/[id]/page.tsx @@ -3,6 +3,7 @@ import { notFound } from "next/navigation"; import { db } from "@/db/client"; import { albumGrants, editorialAccounts } from "@/db/schema"; +import { EditorialDetailContent } from "@/modules/editorials/admin-detail"; export default async function EditorialDetailPage({ params, @@ -33,42 +34,5 @@ export default async function EditorialDetailPage({ ) .limit(1); - return ( -
-

Redaktion

-

{editorial.name}

-
-
Ansprechperson
-
{editorial.contactName}
-
Anmelde-E-Mail
-
{editorial.loginEmail}
-
Status
-
{editorial.status}
-
E-Mail bestätigt
-
{editorial.emailVerifiedAt ? "Ja" : "Nein"}
-
Individueller Nettopreis
-
- {editorial.currentPriceCents === null - ? "Noch nicht festgelegt" - : formatCents(editorial.currentPriceCents)} -
-
- -
-

Freigabe

- -

- {grant - ? "Die Freigabe bleibt bis zur Verwaltungsoberfläche für Albumrechte deaktiviert." - : "Eine Freigabe ist erst möglich, wenn mindestens ein aktives Albumrecht zugewiesen wurde. Die Verwaltung der Albumrechte folgt im nächsten Schritt."} -

-
-
- ); -} - -function formatCents(cents: number): string { - return new Intl.NumberFormat("de-DE", { style: "currency", currency: "EUR" }).format(cents / 100); + return ; } diff --git a/src/modules/editorials/admin-detail.tsx b/src/modules/editorials/admin-detail.tsx new file mode 100644 index 0000000..b1da0f5 --- /dev/null +++ b/src/modules/editorials/admin-detail.tsx @@ -0,0 +1,56 @@ +import Link from "next/link"; + +export type EditorialDetail = { + id: string; + name: string; + contactName: string; + loginEmail: string; + status: string; + emailVerifiedAt: Date | null; + currentPriceCents: number | null; +}; + +export function EditorialDetailContent({ + editorial, + hasActiveGrant, +}: Readonly<{ editorial: EditorialDetail; hasActiveGrant: boolean }>) { + return ( +
+

Redaktion

+

{editorial.name}

+
+
Ansprechperson
+
{editorial.contactName}
+
Anmelde-E-Mail
+
{editorial.loginEmail}
+
Status
+
{editorial.status}
+
E-Mail bestätigt
+
{editorial.emailVerifiedAt ? "Ja" : "Nein"}
+
Individueller Nettopreis
+
+ {editorial.currentPriceCents === null + ? "Noch nicht festgelegt" + : formatCents(editorial.currentPriceCents)} +
+
+ +
+

Freigabe

+ +

+ {hasActiveGrant + ? "Mindestens ein Albumrecht ist zugewiesen. Die Freigabe bleibt bis zur weiteren Verwaltungsoberfläche deaktiviert." + : "Eine Freigabe ist erst möglich, wenn mindestens ein aktives Albumrecht zugewiesen wurde."} +

+ Albumrechte verwalten +
+
+ ); +} + +function formatCents(cents: number): string { + return new Intl.NumberFormat("de-DE", { style: "currency", currency: "EUR" }).format(cents / 100); +}