import { describe, expect, it } from 'vitest'; import { isWorksTokenUsageExhausted } from '@/lib/works-square-token-usage'; describe('isWorksTokenUsageExhausted', () => { it('returns true when either rolling window is exhausted', () => { expect(isWorksTokenUsageExhausted({ five_hour_remaining_percent: 50, weekly_remaining_percent: 0, })).toBe(true); expect(isWorksTokenUsageExhausted({ five_hour_remaining_percent: 0, weekly_remaining_percent: 40, })).toBe(true); }); it('returns false while both rolling windows have remaining allowance', () => { expect(isWorksTokenUsageExhausted({ five_hour_remaining_percent: 50, weekly_remaining_percent: 40, })).toBe(false); }); it('does not treat missing or non-finite usage as confirmed exhaustion', () => { expect(isWorksTokenUsageExhausted(undefined)).toBe(false); expect(isWorksTokenUsageExhausted({ five_hour_remaining_percent: null, weekly_remaining_percent: Number.NaN, })).toBe(false); }); });