Summary of What Needs to be Done:
Add unit tests for the pure and semi-pure functions in src/lib/upstash-rest.ts. Focus on getUpstashConfig() (pure, env-var only) and document the behaviour of upstashPipeline when config is null.
Changes that Need to be Made:
- Create test/upstash-rest.test.ts
- Write tests for getUpstashConfig: mock process.env to verify it returns null when either UPSTASH_REDIS_REST_URL or UPSTASH_REDIS_REST_TOKEN is missing; verify it returns {url, token} when both are set
- Write tests for upstashPipeline when config is null: verify it returns an empty array (safe no-op) without making network calls
- Write tests for upstashRateLimitFixedWindow when config is null: verify it returns {allowed: true} (fail-open for safety)
- Use vi.mock for process.env manipulation within tests
Impact that it would Provide:
These tests ensure that the Upstash client gracefully degrades when credentials are missing, preventing runtime crashes in environments where Redis is not configured. The fail-open behaviour for rate limiting is also validated.
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 and semi-pure functions in src/lib/upstash-rest.ts. Focus on getUpstashConfig() (pure, env-var only) and document the behaviour of upstashPipeline when config is null.
Changes that Need to be Made:
Impact that it would Provide:
These tests ensure that the Upstash client gracefully degrades when credentials are missing, preventing runtime crashes in environments where Redis is not configured. The fail-open behaviour for rate limiting is also validated.
Hello @Priyanshu-byte-coder, please assign this issue to me (@tmdeveloper007) so I can open a focused PR.