Skip to content

Commit 60b2df1

Browse files
authored
test(utils): check boundary robustness of rate limit TTL timers (Variation 3) (JhaSourav07#2229)
## Description Adds a utility verification test to validate sliding time range behavior and ensure keys expire exactly at the configured window boundary. ### Changes Made - Added 1 new test block for the utility function. - Verified behavior across sliding time ranges. - Confirmed that keys remain valid before the window limit and expire exactly at the boundary. ### Testing - Utility verification tests compile successfully. - Existing test suite remains unaffected. Fixes JhaSourav07#1571 ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview <img width="1537" height="768" alt="image" src="https://github.com/user-attachments/assets/a7e4ff33-e7b6-4e62-9d8c-9b8c1b3c5659" /> ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). - [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., `feat(themes): ...`, `fix(calculate): ...`). - [x] 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 fadaeb3 + d5ab85c commit 60b2df1

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

utils/time.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,25 @@ describe('getSecondsUntilUTCMidnight — sliding window boundary robustness', ()
264264
vi.useRealTimers();
265265
});
266266

267+
it('verifies utility guarantees keys expire exactly at window limit across a sliding range', () => {
268+
// Target inputs: Sliding time range approaching midnight in Asia/Kolkata (UTC+5:30)
269+
// Local midnight happens at UTC 18:30:00
270+
const slidingCases: [string, number][] = [
271+
['2024-06-15T17:30:00.000Z', 3600], // 1 hour before local midnight
272+
['2024-06-15T18:00:00.000Z', 1800], // 30 mins before local midnight
273+
['2024-06-15T18:29:59.000Z', 1], // 1 second before local midnight
274+
['2024-06-15T18:30:00.000Z', 86400], // Exactly local midnight (resets to full day)
275+
];
276+
277+
for (const [utcTime, expectedTTL] of slidingCases) {
278+
vi.setSystemTime(new Date(utcTime));
279+
const seconds = getSecondsUntilMidnightInTimezone('Asia/Kolkata');
280+
281+
// Assert that outputs match guarantees keys expire exactly at window limit
282+
expect(seconds).toBe(expectedTTL);
283+
}
284+
});
285+
267286
it('returns correct TTL across a sliding window of times approaching UTC midnight', () => {
268287
// Verifies that the utility guarantees keys expire exactly at the window limit.
269288
// Each entry is [UTC time string, expected seconds until next midnight].

0 commit comments

Comments
 (0)