import { describe, expect, it } from 'bun:test'; import { parseOllamaSettingsHtml, fetchOllamaCloudUsage } from './ollama-cloud.js'; describe('Ollama Cloud quota provider', () => { it('rejects redirects without forwarding credentials', async () => { await expect(fetchOllamaCloudUsage({ cookie: 'session=secret' }, async () => new Response('', { status: 302 }))).rejects.toThrow('authentication failed'); }); it('rejects successful pages without usage data', async () => { await expect(fetchOllamaCloudUsage({ cookie: 'session=secret' }, async () => new Response(''))).rejects.toThrow('could not be parsed'); }); it('parses session/weekly/premium windows', () => { const windows = parseOllamaSettingsHtml('
Session usage: 42%
Weekly usage: 7%
Premium 120 / 1000
'); expect(windows.session.usedPercent).toBe(42); expect(windows.weekly.usedPercent).toBe(7); expect(windows.premium.usedPercent).toBe(12); expect(windows.premium.valueLabel).toBe('120 / 1000'); }); it('parses the cost-based monthly usage shape', () => { const html = 'Monthly usage\n $4.39 of $60 used'; const windows = parseOllamaSettingsHtml(html); expect(windows.monthly.usedPercent).toBeCloseTo(7.3, 1); expect(windows.monthly.valueLabel).toBe('$4.39 / $60'); expect(windows.monthly.remainingPercent).toBeCloseTo(92.7, 1); }); it('parses the extra-usage credits balance', () => { const html = 'Add $5 to your balance when it hits $0
').credits_balance).toBeUndefined(); }); });