32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { buildPagination, 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);
|
|
});
|
|
});
|
|
|
|
describe('buildPagination', () => {
|
|
it('keeps totals at zero when meta total is zero', () => {
|
|
const meta = buildPagination({ meta: { total: 0, per_page: 1, current_page: 1, last_page: 1 } } as any, 1);
|
|
expect(meta.total).toBe(0);
|
|
});
|
|
|
|
it('falls back to data length when total is missing', () => {
|
|
const meta = buildPagination({ data: [] } as any, 1);
|
|
expect(meta.total).toBe(0);
|
|
});
|
|
});
|