|
| 1 | +// services/github/quota-monitor.responsive-breakpoints.test.ts |
| 2 | + |
| 3 | +import { beforeEach, describe, expect, it } from 'vitest'; |
| 4 | +import { quotaMonitor } from './quota-monitor'; |
| 5 | + |
| 6 | +describe('QuotaMonitor Responsive Breakpoint Stability', () => { |
| 7 | + beforeEach(() => { |
| 8 | + quotaMonitor.reset(); |
| 9 | + }); |
| 10 | + |
| 11 | + it('maintains quota data structure under simulated mobile viewport conditions', () => { |
| 12 | + const quota = quotaMonitor.getQuota(); |
| 13 | + |
| 14 | + expect(quota).toEqual({ |
| 15 | + limit: 5000, |
| 16 | + remaining: 5000, |
| 17 | + resetTime: 0, |
| 18 | + totalRefreshes: 0, |
| 19 | + }); |
| 20 | + }); |
| 21 | + |
| 22 | + it('preserves quota values after multiple updates', () => { |
| 23 | + quotaMonitor.setQuota(1000, 750, 123456); |
| 24 | + |
| 25 | + const quota = quotaMonitor.getQuota(); |
| 26 | + |
| 27 | + expect(quota.limit).toBe(1000); |
| 28 | + expect(quota.remaining).toBe(750); |
| 29 | + expect(quota.resetTime).toBe(123456); |
| 30 | + }); |
| 31 | + |
| 32 | + it('handles repeated refresh tracking without state corruption', () => { |
| 33 | + quotaMonitor.incrementRefreshCount(); |
| 34 | + quotaMonitor.incrementRefreshCount(); |
| 35 | + quotaMonitor.incrementRefreshCount(); |
| 36 | + |
| 37 | + expect(quotaMonitor.getQuota().totalRefreshes).toBe(3); |
| 38 | + }); |
| 39 | + |
| 40 | + it('updates state correctly from rate limit headers', () => { |
| 41 | + quotaMonitor.updateQuotaFromHeaders({ |
| 42 | + 'x-ratelimit-limit': '5000', |
| 43 | + 'x-ratelimit-remaining': '250', |
| 44 | + 'x-ratelimit-reset': '1000', |
| 45 | + }); |
| 46 | + |
| 47 | + const quota = quotaMonitor.getQuota(); |
| 48 | + |
| 49 | + expect(quota.limit).toBe(5000); |
| 50 | + expect(quota.remaining).toBe(250); |
| 51 | + expect(quota.resetTime).toBe(1000000); |
| 52 | + }); |
| 53 | + |
| 54 | + it('correctly evaluates low quota thresholds across state transitions', () => { |
| 55 | + quotaMonitor.setQuota(100, 5, Date.now()); |
| 56 | + |
| 57 | + expect(quotaMonitor.isQuotaLow()).toBe(true); |
| 58 | + |
| 59 | + quotaMonitor.setQuota(100, 50, Date.now()); |
| 60 | + |
| 61 | + expect(quotaMonitor.isQuotaLow()).toBe(false); |
| 62 | + }); |
| 63 | +}); |
0 commit comments