29 lines
1.5 KiB
TypeScript
29 lines
1.5 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { permanentBalance as pointBalance } from '../fixtures/permanent-points';
|
|
import {
|
|
formatWorksTokenPointValue,
|
|
isWorksTokenPointBalanceExhausted,
|
|
} from '@/lib/works-square-token-points';
|
|
|
|
describe('permanent token points', () => {
|
|
it('formats exact server point strings without losing integer precision', () => {
|
|
expect(formatWorksTokenPointValue('1000.00')).toBe('1,000');
|
|
expect(formatWorksTokenPointValue('123456789012345678.50')).toBe('123,456,789,012,345,678.5');
|
|
expect(formatWorksTokenPointValue(null)).toBeNull();
|
|
expect(formatWorksTokenPointValue('-1.00')).toBeNull();
|
|
});
|
|
|
|
it('treats an exact zero total balance as exhausted for the owner', () => {
|
|
expect(isWorksTokenPointBalanceExhausted(pointBalance({ total_remaining: '0.00' }))).toBe(true);
|
|
expect(isWorksTokenPointBalanceExhausted(pointBalance())).toBe(false);
|
|
expect(isWorksTokenPointBalanceExhausted(pointBalance({ total_remaining: null }))).toBe(false);
|
|
});
|
|
|
|
it('uses exact personal balance for youth and coarse availability for shared wallets', () => {
|
|
expect(isWorksTokenPointBalanceExhausted(pointBalance({ total_remaining: '0.00', can_recharge: false }))).toBe(true);
|
|
const shared = pointBalance({ family_shared: true, entitlement_source: 'family_owner', total_remaining: null, shared_available: false, can_recharge: false });
|
|
expect(isWorksTokenPointBalanceExhausted(shared)).toBe(true);
|
|
expect(isWorksTokenPointBalanceExhausted({ ...shared, shared_available: true })).toBe(false);
|
|
});
|
|
});
|