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

+32 -3
View File
@@ -56,7 +56,7 @@ function selectedUsage(id: string, status: "open" | "reopened" = "open"): Select
// In-memory mock repository
// ---------------------------------------------------------------------------
function createMockRepo() {
function createMockRepo(options?: { flatratePriceCents?: number | null }) {
const usageStatuses = new Map<string, string>([
["u1", "open"],
["u2", "open"],
@@ -71,7 +71,12 @@ function createMockRepo() {
},
async getEditorialFlatrate() {
return { flatrateActive: false, flatratePriceCents: null, flatrateAssetLimit: null };
const flatratePriceCents = options?.flatratePriceCents ?? null;
return {
flatrateActive: flatratePriceCents !== null,
flatratePriceCents,
flatrateAssetLimit: null,
};
},
async getSelectedUsages(_editorialId, usageIds) {
@@ -247,6 +252,30 @@ test("previewReport returns PDF bytes without persisting or billing", async () =
await expect(repo.getUsageStatuses(validSelection.usageIds)).resolves.toEqual(["open", "open"]);
});
test("uses the server-read flatrate snapshot consistently in PDF, total, and persistence", async () => {
const { repo, reports } = createMockRepo({ flatratePriceCents: 12_500 });
const finalizeInTransaction = vi.spyOn(repo, "finalizeInTransaction");
const { service, render } = createService(repo);
const result = await service.finalizeReport(validSelection);
expect(render).toHaveBeenCalledWith(
expect.objectContaining({
flatrateCentsSnapshot: 12_500,
netTotalCents: 18_500,
}),
);
expect(finalizeInTransaction).toHaveBeenCalledWith(
expect.objectContaining({
flatrateCentsSnapshot: 12_500,
netTotalCents: 18_500,
}),
);
await expect(repo.getReport(result.reportId)).resolves.toMatchObject({
netTotalCents: 18_500,
});
});
test("finalizeReport rejects when a selected usage is already billed", async () => {
const mock = createMockRepo();
const { repo } = mock;
@@ -273,4 +302,4 @@ test("cancelReport rejects a reason longer than 500 characters", async () => {
await expect(
service.cancelReport({ reportId: "r1", reason: "x".repeat(501), adminUserId: "a1" }),
).rejects.toThrow();
});
});