Summary of What Needs to be Done:
Add unit tests for the pure helper functions exported from src/lib/leaderboard.ts: validateUserConcurrency, isFresh, and generateCacheKey.
Changes that Need to be Made:
- Create test/leaderboard-helpers.test.ts
- Write tests for validateUserConcurrency: returns default 5 when env var is unset; returns 5 when env var is non-numeric string; clamps to 1 when value is 0 or negative; clamps to 100 when value exceeds 100; returns the integer value when within [1, 100]; logs warning for out-of-range values
- Write tests for isFresh: returns true when payload.generatedAt is within CACHE_REFRESH_SECONDS; returns false when payload is stale or has invalid timestamp; handles edge case of generatedAt exactly at the boundary
- Write tests for generateCacheKey: returns a string containing the period; different periods produce different keys
- Tests should not require network access or database connections
Impact that it would Provide:
These pure helpers drive critical caching and concurrency behaviour in the leaderboard API. Testing them explicitly guards against regressions that could cause cache stampedes or invalid concurrency settings.
Hello @Priyanshu-byte-coder, please assign this issue to me (@tmdeveloper007) so I can open a focused PR.
Summary of What Needs to be Done:
Add unit tests for the pure helper functions exported from src/lib/leaderboard.ts: validateUserConcurrency, isFresh, and generateCacheKey.
Changes that Need to be Made:
Impact that it would Provide:
These pure helpers drive critical caching and concurrency behaviour in the leaderboard API. Testing them explicitly guards against regressions that could cause cache stampedes or invalid concurrency settings.
Hello @Priyanshu-byte-coder, please assign this issue to me (@tmdeveloper007) so I can open a focused PR.