Show event-per-purchase for endcustomer packages
This commit is contained in:
@@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user