fix: harden production flows and user messaging

This commit is contained in:
Leon Tonhäuser committed 2026-08-11 16:07:13 +02:00
1 parent 52dce168dd
commit 86dfe8053d
43 files changed
+3520 -358

No files matched your search

@@ -30,6 +30,7 @@ function dependencies() {
status: "authorized",
authorizedAt: new Date("2026-08-10T10:00:00.000Z"),
}),
consumeRateLimit: vi.fn().mockResolvedValue({ allowed: true, retryAfterSeconds: 0 }),
};
}
@@ -138,3 +139,23 @@ test("passes one submitted idempotency key through unchanged", async () => {
expect(deps.createNewUsage).toHaveBeenNthCalledWith(1, expect.objectContaining({ idempotencyKey }));
expect(deps.createNewUsage).toHaveBeenNthCalledWith(2, expect.objectContaining({ idempotencyKey }));
});
test("returns retry-after without creating an intent when the editorial limit is exhausted", async () => {
const deps = dependencies();
deps.consumeRateLimit.mockResolvedValue({ allowed: false, retryAfterSeconds: 23 });
const response = await post(createDownloadIntentHandler(deps), {
kind: "new_usage",
assetId,
albumId,
purpose: "Titelgeschichte",
idempotencyKey,
});
expect(response.status).toBe(429);
expect(response.headers.get("retry-after")).toBe("23");
expect(deps.consumeRateLimit).toHaveBeenCalledWith(
`download-intent:${editorialId}`,
expect.any(Object),
);
expect(deps.createNewUsage).not.toHaveBeenCalled();
});