forked from JhaSourav07/commitpulse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquota-monitor.timezone-boundaries.test.ts
More file actions
69 lines (51 loc) · 2.02 KB
/
Copy pathquota-monitor.timezone-boundaries.test.ts
File metadata and controls
69 lines (51 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { beforeEach, describe, expect, it } from 'vitest';
import quotaMonitor from './quota-monitor';
describe('QuotaMonitor Timezone Boundaries', () => {
beforeEach(() => {
quotaMonitor.reset();
});
it('stores UTC midnight reset timestamps correctly', () => {
const utcMidnight = 1704067200; // 2024-01-01T00:00:00Z
quotaMonitor.updateQuotaFromHeaders({
'x-ratelimit-reset': String(utcMidnight),
});
expect(quotaMonitor.getQuota().resetTime).toBe(1704067200000);
});
it('preserves reset timestamps near EST calendar boundaries', () => {
const estBoundary = 1704085199;
quotaMonitor.updateQuotaFromHeaders({
'x-ratelimit-reset': String(estBoundary),
});
expect(quotaMonitor.getQuota().resetTime).toBe(estBoundary * 1000);
});
it('updates correctly when moving between IST and JST boundary timestamps', () => {
const istBoundary = 1704047400;
const jstBoundary = 1704034800;
quotaMonitor.updateQuotaFromHeaders({
'x-ratelimit-reset': String(istBoundary),
});
expect(quotaMonitor.getQuota().resetTime).toBe(istBoundary * 1000);
quotaMonitor.updateQuotaFromHeaders({
'x-ratelimit-reset': String(jstBoundary),
});
expect(quotaMonitor.getQuota().resetTime).toBe(jstBoundary * 1000);
});
it('handles leap year reset dates without losing precision', () => {
const leapYearReset = Math.floor(new Date('2024-02-29T00:00:00Z').getTime() / 1000);
quotaMonitor.updateQuotaFromHeaders({
'x-ratelimit-reset': String(leapYearReset),
});
expect(quotaMonitor.getQuota().resetTime).toBe(leapYearReset * 1000);
});
it('tracks DST transition timestamps while preserving quota state', () => {
quotaMonitor.updateQuotaFromHeaders({
'x-ratelimit-limit': '5000',
'x-ratelimit-remaining': '4500',
'x-ratelimit-reset': '1710054000',
});
const quota = quotaMonitor.getQuota();
expect(quota.limit).toBe(5000);
expect(quota.remaining).toBe(4500);
expect(quota.resetTime).toBe(1710054000000);
});
});