|
| 1 | +// services/github/quota-monitor.accessibility.test.ts |
| 2 | + |
| 3 | +import { beforeEach, describe, expect, it } from 'vitest'; |
| 4 | +import { quotaMonitor } from './quota-monitor'; |
| 5 | + |
| 6 | +describe('QuotaMonitor Accessibility & State Visibility', () => { |
| 7 | + beforeEach(() => { |
| 8 | + quotaMonitor.reset(); |
| 9 | + }); |
| 10 | + |
| 11 | + it('exposes quota information in a readable structure', () => { |
| 12 | + const quota = quotaMonitor.getQuota(); |
| 13 | + |
| 14 | + expect(quota).toHaveProperty('limit'); |
| 15 | + expect(quota).toHaveProperty('remaining'); |
| 16 | + expect(quota).toHaveProperty('resetTime'); |
| 17 | + expect(quota).toHaveProperty('totalRefreshes'); |
| 18 | + }); |
| 19 | + |
| 20 | + it('updates quota values from standard GitHub rate limit headers', () => { |
| 21 | + quotaMonitor.updateQuotaFromHeaders({ |
| 22 | + 'x-ratelimit-limit': '5000', |
| 23 | + 'x-ratelimit-remaining': '1234', |
| 24 | + 'x-ratelimit-reset': '1000', |
| 25 | + }); |
| 26 | + |
| 27 | + const quota = quotaMonitor.getQuota(); |
| 28 | + |
| 29 | + expect(quota.limit).toBe(5000); |
| 30 | + expect(quota.remaining).toBe(1234); |
| 31 | + expect(quota.resetTime).toBe(1000000); |
| 32 | + }); |
| 33 | + |
| 34 | + it('maintains logical state hierarchy after manual quota updates', () => { |
| 35 | + quotaMonitor.setQuota(100, 50, 123456); |
| 36 | + |
| 37 | + const quota = quotaMonitor.getQuota(); |
| 38 | + |
| 39 | + expect(quota.limit).toBe(100); |
| 40 | + expect(quota.remaining).toBe(50); |
| 41 | + expect(quota.resetTime).toBe(123456); |
| 42 | + }); |
| 43 | + |
| 44 | + it('tracks refresh counts for status visibility', () => { |
| 45 | + quotaMonitor.incrementRefreshCount(); |
| 46 | + quotaMonitor.incrementRefreshCount(); |
| 47 | + |
| 48 | + const quota = quotaMonitor.getQuota(); |
| 49 | + |
| 50 | + expect(quota.totalRefreshes).toBe(2); |
| 51 | + }); |
| 52 | + |
| 53 | + it('flags low quota state correctly for user-facing warnings', () => { |
| 54 | + quotaMonitor.setQuota(100, 5, Date.now()); |
| 55 | + |
| 56 | + expect(quotaMonitor.isQuotaLow()).toBe(true); |
| 57 | + |
| 58 | + quotaMonitor.setQuota(100, 50, Date.now()); |
| 59 | + |
| 60 | + expect(quotaMonitor.isQuotaLow()).toBe(false); |
| 61 | + }); |
| 62 | +}); |
0 commit comments