Skip to content

Commit 401f4ca

Browse files
authored
test(cache): verify TTLCache behavior for empty string keys (Variation 2) (JhaSourav07#1402) (JhaSourav07#2197)
## Description Fixes JhaSourav07#1402 ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview ## 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): ...`). - [ ] 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). - [x] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support. --- I have tested every tests for these changes. <img width="997" height="126" alt="Screenshot 2026-06-01 020511" src="https://github.com/user-attachments/assets/598e9b04-a4bb-486f-b219-ec2ab55ffd85" />
2 parents 0b36178 + 6f8882a commit 401f4ca

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

lib/cache.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,34 @@ describe('TTLCache', () => {
504504
cache.destroy();
505505
});
506506

507+
it('verify TTLCache behavior for empty string keys (Variation 2)', () => {
508+
const cache = new TTLCache<string>();
509+
510+
// Assert that setting a value with empty string key throws error
511+
expect(() => {
512+
cache.set('', 'test-value', 60_000);
513+
}).toThrow(Error);
514+
515+
// Verify the error message is correct
516+
expect(() => {
517+
cache.set('', 'test-value', 60_000);
518+
}).toThrow('Cache key cannot be empty');
519+
520+
// Verify that cache remains empty (no entry for empty key)
521+
expect(cache.has('')).toBe(false);
522+
expect(cache.get('')).toBeNull();
523+
524+
// Verify cache size is still 0
525+
expect(cache.size()).toBe(0);
526+
527+
// Verify that normal operations still work after failed attempt
528+
cache.set('valid-key', 'value', 60_000);
529+
expect(cache.get('valid-key')).toBe('value');
530+
expect(cache.size()).toBe(1);
531+
532+
cache.destroy();
533+
});
534+
507535
it('handles rapid get/set/delete cycles', () => {
508536
const cache = new TTLCache<number>();
509537
for (let i = 0; i < 100; i++) {

0 commit comments

Comments
 (0)