Skip to content

Commit a1beebc

Browse files
authored
test(utils): add boundary robustness test for rate limit TTL timers (JhaSourav07#1655)
## Description Added a sliding window boundary robustness test for `getSecondsUntilUTCMidnight` in `utils/time.test.ts`. The test verifies that the utility returns the correct TTL value across a range of times approaching UTC midnight, ensuring keys expire exactly at the window limit. Changes - Added a new test in `utils/time.test.ts` - Simulated a sliding window of times approaching UTC midnight - Verified correct TTL is returned at each boundary point - Verified the value resets to 86400 exactly at midnight Fixes JhaSourav07#1551 ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) Visual Preview N/A (test-only change) ## Checklist - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally (`npm run test -- utils/time.test.ts`). - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). - [x] My commits follow the Conventional Commits format (e.g., `test(utils): ...`). - [ ] I have updated `README.md` if I added a new theme or URL parameter. - [x] I have started the repo. - [x] I have made sure that i have only one commit to merge in this PR. - [x] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). - [ ] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents 9f45384 + e1f5bca commit a1beebc

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

utils/time.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,31 @@ describe('getSecondsUntilMidnightInTimezone', () => {
152152
expect(getSecondsUntilMidnightInTimezone('Etc/GMT-14')).toBe(10 * 3600);
153153
});
154154
});
155+
156+
describe('getSecondsUntilUTCMidnight — sliding window boundary robustness', () => {
157+
beforeEach(() => {
158+
vi.useFakeTimers();
159+
});
160+
161+
afterEach(() => {
162+
vi.useRealTimers();
163+
});
164+
165+
it('returns correct TTL across a sliding window of times approaching UTC midnight', () => {
166+
// Verifies that the utility guarantees keys expire exactly at the window limit.
167+
// Each entry is [UTC time string, expected seconds until next midnight].
168+
const cases: [string, number][] = [
169+
['2024-06-15T23:00:00.000Z', 3600], // 1 hour before midnight
170+
['2024-06-15T23:30:00.000Z', 1800], // 30 minutes before midnight
171+
['2024-06-15T23:45:00.000Z', 900], // 15 minutes before midnight
172+
['2024-06-15T23:59:00.000Z', 60], // 1 minute before midnight
173+
['2024-06-15T23:59:59.000Z', 1], // 1 second before midnight
174+
['2024-06-16T00:00:00.000Z', 86400], // exactly at midnight, resets to full day
175+
];
176+
177+
for (const [time, expected] of cases) {
178+
vi.setSystemTime(new Date(time));
179+
expect(getSecondsUntilUTCMidnight()).toBe(expected);
180+
}
181+
});
182+
});

0 commit comments

Comments
 (0)