Skip to content

Add unit tests for SimpleCache in src/utils/cache.ts #116

Description

@meshackyaro

Description

SimpleCache<K, V> (src/utils/cache.ts) implements TTL expiry (set/get/delete/clear/size, with per-entry and default TTLs), but has no test file exercising it — none of tests/utils.test.ts or any other test file references SimpleCache or utils/cache. Its expiry logic (Date.now() > entry.expiresAt, lazily evicting on get) is exactly the kind of time-dependent code that's easy to get subtly wrong (off-by-one on the boundary, forgetting to delete on expiry) without a test using fake timers.

Component

SDK

Difficulty

🟢 Easy

Tasks

  • Add tests/cache.test.ts covering set/get round-trip, delete, clear, size
  • Use Jest fake timers to test TTL expiry (both the default TTL and a per-call override) and confirm an expired entry is evicted from the underlying Map on get
  • This can be done independently of the decision in the companion "wire up or remove SimpleCache" issue — tests are useful either way until that's resolved

Acceptance Criteria

  • tests/cache.test.ts exists and covers expiry behavior with fake timers

Estimated Time

<1 day

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions