Preserve null remaining_events in package normalization
This commit is contained in:
19
resources/js/admin/__tests__/api.test.ts
Normal file
19
resources/js/admin/__tests__/api.test.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user