Preserve null remaining_events in package normalization
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled

This commit is contained in:
Codex Agent
2026-01-16 14:11:44 +01:00
parent 05fdda811b
commit 4c37f874bd
2 changed files with 22 additions and 2 deletions

View File

@@ -0,0 +1,19 @@
import { describe, expect, it } from 'vitest';
import { normalizeTenantPackage } from '../api';
describe('normalizeTenantPackage', () => {
it('keeps remaining_events null when payload is null', () => {
const normalized = normalizeTenantPackage({ id: 1, remaining_events: null, used_events: 0 } as any);
expect(normalized.remaining_events).toBeNull();
});
it('keeps remaining_events null when payload is missing', () => {
const normalized = normalizeTenantPackage({ id: 1, used_events: 0 } as any);
expect(normalized.remaining_events).toBeNull();
});
it('coerces remaining_events to number when provided', () => {
const normalized = normalizeTenantPackage({ id: 1, remaining_events: '2', used_events: 0 } as any);
expect(normalized.remaining_events).toBe(2);
});
});

View File

@@ -1011,7 +1011,7 @@ function normalizeDashboard(payload: JsonValue | null): DashboardSummary | null
};
}
function normalizeTenantPackage(pkg: JsonValue): TenantPackageSummary {
export function normalizeTenantPackage(pkg: JsonValue): TenantPackageSummary {
const packageData = pkg.package ?? {};
return {
id: Number(pkg.id ?? 0),
@@ -1031,7 +1031,8 @@ function normalizeTenantPackage(pkg: JsonValue): TenantPackageSummary {
: null,
active: Boolean(pkg.active ?? false),
used_events: Number(pkg.used_events ?? 0),
remaining_events: pkg.remaining_events !== undefined ? Number(pkg.remaining_events) : null,
remaining_events:
pkg.remaining_events === undefined || pkg.remaining_events === null ? null : Number(pkg.remaining_events),
price: packageData.price !== undefined ? Number(packageData.price) : pkg.price ?? null,
currency: packageData.currency ?? pkg.currency ?? 'EUR',
purchased_at: pkg.purchased_at ?? pkg.created_at ?? null,