Show event-per-purchase for endcustomer packages
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:00:12 +01:00
parent fa6a5678f0
commit eeeca0eed5
5 changed files with 73 additions and 12 deletions

View File

@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';
import type { TenantPackageSummary } from '../../api';
import { buildPackageUsageMetrics, getUsageState, usagePercent } from '../billingUsage';
import { buildPackageUsageMetrics, formatPackageEventAllowance, getUsageState, usagePercent } from '../billingUsage';
const basePackage: TenantPackageSummary = {
id: 1,
@@ -92,3 +92,34 @@ describe('getUsageState', () => {
expect(getUsageState({ ...metrics[0], used: 10, remaining: 0 })).toBe('danger');
});
});
describe('formatPackageEventAllowance', () => {
const t = (key: string, options?: Record<string, unknown>) => {
if (key === 'mobileBilling.eventPerPurchase') {
return String(options?.defaultValue ?? '1 event per purchase');
}
if (key === 'mobileBilling.remainingEventsZero') {
return String(options?.defaultValue ?? 'No events remaining');
}
if (key === 'mobileBilling.remainingEventsOf') {
return `${options?.remaining} of ${options?.limit} events remaining`;
}
if (key === 'mobileBilling.remainingEvents') {
return `${options?.count} events`;
}
return key;
};
it('returns event-per-purchase for endcustomer packages', () => {
const label = formatPackageEventAllowance(
{ ...basePackage, package_type: 'endcustomer', remaining_events: null },
t
);
expect(label).toBe('1 event per purchase');
});
it('returns remaining events for reseller packages', () => {
const label = formatPackageEventAllowance(basePackage, t);
expect(label).toBe('3 of 5 events remaining');
});
});