fix: harden download history and attempt ledger
This commit is contained in:
1 parent
510fde7afa
commit
ba673ad732
19 files changed
+2287
-311
No files matched your search
@@ -22,35 +22,81 @@ test("renders every terminal attempt with its immutable usage snapshot", () => {
|
||||
billingStatus: "open",
|
||||
priceCents: 1_500,
|
||||
billableCents: 1_500,
|
||||
attempts: [
|
||||
{
|
||||
downloadId: "download-3",
|
||||
status: "failed_before_delivery",
|
||||
requestedAt: new Date("2026-08-10T12:00:00.000Z"),
|
||||
finishedAt: new Date("2026-08-10T12:00:01.000Z"),
|
||||
transferredBytes: 0,
|
||||
repeat: true,
|
||||
billableCents: 0,
|
||||
},
|
||||
{
|
||||
downloadId: "download-2",
|
||||
status: "interrupted",
|
||||
requestedAt: new Date("2026-08-10T11:00:00.000Z"),
|
||||
finishedAt: new Date("2026-08-10T11:00:02.000Z"),
|
||||
transferredBytes: 40,
|
||||
repeat: true,
|
||||
billableCents: 0,
|
||||
},
|
||||
{
|
||||
downloadId: "download-1",
|
||||
status: "completed",
|
||||
requestedAt: new Date("2026-08-09T10:00:00.000Z"),
|
||||
finishedAt: new Date("2026-08-09T10:00:03.000Z"),
|
||||
transferredBytes: 100,
|
||||
repeat: false,
|
||||
billableCents: 1_500,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
attempts: [
|
||||
{
|
||||
downloadId: "download-5",
|
||||
usageId: "usage-1",
|
||||
status: "authorized",
|
||||
requestedAt: new Date("2026-08-10T13:00:00.000Z"),
|
||||
transferredBytes: 0,
|
||||
repeat: true,
|
||||
billableCents: 0,
|
||||
filename: "tor-des-monats.jpg",
|
||||
albumName: "Heimspiel gegen Nord",
|
||||
purpose: "Titelgeschichte",
|
||||
reference: "Ausgabe 8/26",
|
||||
priceCents: 1_500,
|
||||
},
|
||||
{
|
||||
downloadId: "download-4",
|
||||
usageId: "usage-1",
|
||||
status: "streaming",
|
||||
requestedAt: new Date("2026-08-10T12:30:00.000Z"),
|
||||
transferredBytes: 0,
|
||||
repeat: true,
|
||||
billableCents: 0,
|
||||
filename: "tor-des-monats.jpg",
|
||||
albumName: "Heimspiel gegen Nord",
|
||||
purpose: "Titelgeschichte",
|
||||
reference: "Ausgabe 8/26",
|
||||
priceCents: 1_500,
|
||||
},
|
||||
{
|
||||
downloadId: "download-3",
|
||||
usageId: "usage-1",
|
||||
status: "failed_before_delivery",
|
||||
requestedAt: new Date("2026-08-10T12:00:00.000Z"),
|
||||
finishedAt: new Date("2026-08-10T12:00:01.000Z"),
|
||||
transferredBytes: 0,
|
||||
repeat: true,
|
||||
billableCents: 0,
|
||||
filename: "tor-des-monats.jpg",
|
||||
albumName: "Heimspiel gegen Nord",
|
||||
purpose: "Titelgeschichte",
|
||||
reference: "Ausgabe 8/26",
|
||||
priceCents: 1_500,
|
||||
},
|
||||
{
|
||||
downloadId: "download-2",
|
||||
usageId: "usage-1",
|
||||
status: "interrupted",
|
||||
requestedAt: new Date("2026-08-10T11:00:00.000Z"),
|
||||
finishedAt: new Date("2026-08-10T11:00:02.000Z"),
|
||||
transferredBytes: 40,
|
||||
repeat: true,
|
||||
billableCents: 0,
|
||||
filename: "tor-des-monats.jpg",
|
||||
albumName: "Heimspiel gegen Nord",
|
||||
purpose: "Titelgeschichte",
|
||||
reference: "Ausgabe 8/26",
|
||||
priceCents: 1_500,
|
||||
},
|
||||
{
|
||||
downloadId: "download-1",
|
||||
usageId: "usage-1",
|
||||
status: "completed",
|
||||
requestedAt: new Date("2026-08-09T10:00:00.000Z"),
|
||||
finishedAt: new Date("2026-08-09T10:00:03.000Z"),
|
||||
transferredBytes: 100,
|
||||
repeat: false,
|
||||
billableCents: 1_500,
|
||||
filename: "tor-des-monats.jpg",
|
||||
albumName: "Heimspiel gegen Nord",
|
||||
purpose: "Titelgeschichte",
|
||||
reference: "Ausgabe 8/26",
|
||||
priceCents: 1_500,
|
||||
},
|
||||
],
|
||||
page: 1,
|
||||
@@ -69,8 +115,12 @@ test("renders every terminal attempt with its immutable usage snapshot", () => {
|
||||
expect(screen.getByText("Abgeschlossen")).not.toBeNull();
|
||||
expect(screen.getByText("Unterbrochen")).not.toBeNull();
|
||||
expect(screen.getByText("Vor Auslieferung fehlgeschlagen")).not.toBeNull();
|
||||
expect(screen.getAllByText(/15,00\s*€/)).toHaveLength(2);
|
||||
expect(screen.getAllByText(/0,00\s*€/)).toHaveLength(2);
|
||||
expect(screen.getByText("Autorisiert")).not.toBeNull();
|
||||
expect(screen.getByText("Wird ausgeliefert")).not.toBeNull();
|
||||
expect(screen.getByRole("heading", { name: "Downloadversuche" })).not.toBeNull();
|
||||
expect(screen.getAllByText(/Nutzungspreis\s+15,00\s*€/)).toHaveLength(5);
|
||||
expect(screen.getAllByText(/15,00\s*€/)).toHaveLength(7);
|
||||
expect(screen.getAllByText(/0,00\s*€/)).toHaveLength(4);
|
||||
expect(screen.getByRole("link", { name: /nächste nutzungsseite/i }).getAttribute("href")).toBe(
|
||||
"/redaktion/nutzungen?page=2",
|
||||
);
|
||||
@@ -89,6 +139,7 @@ test("renders a directional empty state", () => {
|
||||
<UsageHistoryContent
|
||||
history={{
|
||||
items: [],
|
||||
attempts: [],
|
||||
page: 1,
|
||||
pageSize: 20,
|
||||
hasNext: false,
|
||||
@@ -115,9 +166,9 @@ test("shows the usage-level price and billing status before any attempt is termi
|
||||
billingStatus: "open",
|
||||
priceCents: 1_500,
|
||||
billableCents: 1_500,
|
||||
attempts: [],
|
||||
},
|
||||
],
|
||||
attempts: [],
|
||||
page: 1,
|
||||
pageSize: 20,
|
||||
hasNext: false,
|
||||
@@ -145,9 +196,9 @@ test("keeps the immutable usage price visible when billing was voided", () => {
|
||||
billingStatus: "voided",
|
||||
priceCents: 1_500,
|
||||
billableCents: 0,
|
||||
attempts: [],
|
||||
},
|
||||
],
|
||||
attempts: [],
|
||||
page: 1,
|
||||
pageSize: 20,
|
||||
hasNext: false,
|
||||
|
||||
@@ -63,17 +63,6 @@ export function UsageHistoryContent({ history }: Readonly<{ history: UsageHistor
|
||||
</div>
|
||||
) : null}
|
||||
</dl>
|
||||
{usage.attempts.length === 0 ? (
|
||||
<p className="usage-attempt-empty">
|
||||
Keine Auslieferungsversuche auf dieser Auslieferungsseite.
|
||||
</p>
|
||||
) : (
|
||||
<ol className="usage-attempts" aria-label={`Auslieferungen für ${usage.filename}`}>
|
||||
{usage.attempts.map((attempt) => (
|
||||
<AttemptRow attempt={attempt} key={attempt.downloadId} />
|
||||
))}
|
||||
</ol>
|
||||
)}
|
||||
</article>
|
||||
</li>
|
||||
))}
|
||||
@@ -81,21 +70,47 @@ export function UsageHistoryContent({ history }: Readonly<{ history: UsageHistor
|
||||
)}
|
||||
|
||||
<HistoryPagination history={history} />
|
||||
|
||||
<section className="usage-attempt-history" aria-labelledby="usage-attempt-title">
|
||||
<h2 id="usage-attempt-title">Downloadversuche</h2>
|
||||
{history.attempts.length === 0 ? (
|
||||
<p className="usage-attempt-empty">Noch keine Downloadversuche erfasst.</p>
|
||||
) : (
|
||||
<ol className="usage-attempts" aria-label="Downloadversuche Ihrer Redaktion">
|
||||
{history.attempts.map((attempt) => (
|
||||
<AttemptRow attempt={attempt} key={attempt.downloadId} />
|
||||
))}
|
||||
</ol>
|
||||
)}
|
||||
</section>
|
||||
<AttemptPagination history={history} />
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function AttemptRow({ attempt }: Readonly<{ attempt: UsageHistoryAttempt }>) {
|
||||
const displayedAt = attempt.finishedAt ?? attempt.requestedAt;
|
||||
return (
|
||||
<li>
|
||||
<time dateTime={attempt.finishedAt.toISOString()}>
|
||||
{formatBerlinDateTime(attempt.finishedAt)}
|
||||
<time dateTime={displayedAt.toISOString()}>
|
||||
{formatBerlinDateTime(displayedAt)}
|
||||
</time>
|
||||
<span className="usage-attempt-context">
|
||||
<strong>{attempt.filename}</strong>
|
||||
<small>
|
||||
{attempt.albumName} · {attempt.purpose}
|
||||
{attempt.reference ? ` · ${attempt.reference}` : ""}
|
||||
</small>
|
||||
</span>
|
||||
<strong>{statusLabel(attempt.status)}</strong>
|
||||
<span>{attempt.repeat ? "Wiederholter Abruf" : "Neue Nutzung"}</span>
|
||||
<span>{byteFormatter.format(attempt.transferredBytes)}</span>
|
||||
<b>{priceFormatter.format(attempt.billableCents / 100)}</b>
|
||||
<span>
|
||||
{attempt.repeat ? "Wiederholter Abruf" : "Neue Nutzung"} ·{" "}
|
||||
{byteFormatter.format(attempt.transferredBytes)}
|
||||
</span>
|
||||
<span className="usage-attempt-price">
|
||||
<b>{priceFormatter.format(attempt.billableCents / 100)}</b>
|
||||
<small>Nutzungspreis {priceFormatter.format(attempt.priceCents / 100)}</small>
|
||||
</span>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
@@ -142,6 +157,8 @@ function AttemptPagination({ history }: Readonly<{ history: UsageHistoryPage }>)
|
||||
|
||||
function statusLabel(status: UsageHistoryAttempt["status"]): string {
|
||||
const labels: Record<UsageHistoryAttempt["status"], string> = {
|
||||
authorized: "Autorisiert",
|
||||
streaming: "Wird ausgeliefert",
|
||||
completed: "Abgeschlossen",
|
||||
interrupted: "Unterbrochen",
|
||||
failed_before_delivery: "Vor Auslieferung fehlgeschlagen",
|
||||
|
||||
Reference in new issue
Block a user