Skip to content

Commit 6e6879b

Browse files
authored
test(cache): verify TTLCache behavior for Date instance values (Variation 1) (JhaSourav07#1397) (JhaSourav07#2195)
## Description Fixes JhaSourav07#1397 ## 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 also run the tests locally and verified them - <img width="950" height="142" alt="Screenshot 2026-06-01 011528" src="https://github.com/user-attachments/assets/f61ac948-8ae5-4e17-b80b-f5db9ba3e68b" />
2 parents 401f4ca + 811947a commit 6e6879b

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

lib/cache.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,51 @@ describe('TTLCache', () => {
447447
cache.destroy();
448448
});
449449

450+
it('preserves Date instance with current timestamp (new Date())', () => {
451+
const cache = new TTLCache<Date>();
452+
453+
const now = new Date();
454+
455+
cache.set('current-date', now, 60_000);
456+
457+
const cached = cache.get('current-date');
458+
459+
expect(cached).toBeInstanceOf(Date);
460+
expect(cached?.getTime()).toBe(now.getTime());
461+
expect(cached?.toISOString()).toBe(now.toISOString());
462+
463+
cache.destroy();
464+
});
465+
466+
it('preserves Date instance nested in object with mixed types', () => {
467+
const cache = new TTLCache<{
468+
id: number;
469+
name: string;
470+
created: Date;
471+
isActive: boolean;
472+
}>();
473+
474+
const created = new Date('2024-03-15T10:30:45.123Z');
475+
const data = {
476+
id: 42,
477+
name: 'Test Event',
478+
created: created,
479+
isActive: true,
480+
};
481+
482+
cache.set('event', data, 60_000);
483+
484+
const cached = cache.get('event');
485+
486+
expect(cached?.id).toBe(42);
487+
expect(cached?.name).toBe('Test Event');
488+
expect(cached?.isActive).toBe(true);
489+
expect(cached?.created).toBeInstanceOf(Date);
490+
expect(cached?.created.toISOString()).toBe(created.toISOString());
491+
492+
cache.destroy();
493+
});
494+
450495
it('stores and retrieves nested object values', () => {
451496
const cache = new TTLCache<{
452497
user: { id: number; name: string };

0 commit comments

Comments
 (0)