Skip to content

Merge pull request #148 from contentstack/enh/retry-unit-testcases

c60893c
Select commit
Loading
Failed to load commit list.
Sign in for the full log view
Merged

DX | 03-11-2025 | Release #145

Merge pull request #148 from contentstack/enh/retry-unit-testcases
c60893c
Select commit
Loading
Failed to load commit list.
GitHub Actions / JEST Tests succeeded Oct 31, 2025 in 0s

76 passed, 0 failed and 0 skipped

Tests passed successfully

✅ reports/contentstack-js-core/junit/jest-junit.xml

76 tests were completed in 6s with 76 passed, 0 failed and 0 skipped.

Test suite Passed Failed Skipped Time
test/contentstack-core.spec.ts 13✅ 4s
test/contentstack-error.spec.ts 4✅ 88ms
test/param-serializer.spec.ts 5✅ 72ms
test/request.spec.ts 19✅ 4s
test/retryPolicy/delivery-sdk-handlers.spec.ts 35✅ 4s

✅ test/contentstack-core.spec.ts

contentstackCore
  ✅ should return default config when no config is passed
contentstackCore › logHandler
  ✅ should log an error message when level is "error" and data is provided
  ✅ should not log anything when level is "error" and no data is provided
  ✅ should log a message with the provided level and data
contentstackCore › retryCondition
  ✅ should return true when error response status is 429
  ✅ should return false when error response status is not 429
  ✅ should return false when error response is not present
contentstackCore › config.headers
  ✅ should include apiKey in headers when provided
  ✅ should include accessToken in headers when provided
  ✅ should not include apiKey in headers when not provided
  ✅ should not include accessToken in headers when not provided
contentstackCore › config.onError
  ✅ should call the onError function when an error occurs
  ✅ should not call the onError function when no error occurs

✅ test/contentstack-error.spec.ts

Contentstack Error
  ✅ should throw an error with proper details
  ✅ should throw an error with a default message if response or config is not present
  ✅ should throw an error with a default details if response data is not present
  ✅ should throw an error with proper details when response.data is not available

✅ test/param-serializer.spec.ts

serialize
  ✅ should return blank string when passed empty params
  ✅ should return brackets structure when param contains array value
  ✅ should return non brackets string when param value is not array value
  ✅ should return query with encode string when passed query param
  ✅ should return brackets and query with encoded string when passed query param and array value

✅ test/request.spec.ts

Request tests
  ✅ should fetch successfully data from an API
  ✅ should handle errors
  ✅ should throw error when host is required for live preview
  ✅ should handle live_preview with enable=true and live_preview=init
  ✅ should set baseURL correctly when host is provided without https://
  ✅ should not modify baseURL when host is already prefixed with https://
  ✅ should throw error when response has no data property
  ✅ should throw error when response is null
  ✅ should handle live_preview when enable is false
  ✅ should handle request when stackConfig is undefined
  ✅ should handle request when stackConfig exists but live_preview is undefined
  ✅ should set live_preview to "init" when enable is true and no live_preview provided
  ✅ should set headers when preview_token is provided
  ✅ should handle live_preview when enable is true but no preview_token
  ✅ should handle custom error messages when request fails
  ✅ should handle non-Error objects as errors when they have message property
  ✅ should handle non-Error objects as errors when they have no message property
  ✅ should pass data parameter to axios get request
  ✅ should handle React Native compatibility by avoiding URLSearchParams.set()

✅ test/retryPolicy/delivery-sdk-handlers.spec.ts

retryRequestHandler
  ✅ should add retryCount to the request config
retryResponseHandler
  ✅ should return the response as-is
retryResponseErrorHandler
  ✅ should reject the promise if retryOnError is false
  ✅ should reject the promise if retryOnError is true
  ✅ should resolve the promise to 408 error if retryOnError is true and error code is ECONNABORTED
  ✅ should reject the promise if response status is 429 and retryCount exceeds retryLimit
  ✅ should reject the promise if response status is 401 and retryCount exceeds retryLimit
  ✅ should reject the promise if response status is 429 or 401 and retryCount is within limit
  ✅ should call the retry function if retryCondition is passed
  ✅ should reject to error when retryCondition is passed but retryLimit is exceeded
  ✅ should retry when response status is 429 and retryCount is less than retryLimit
  ✅ should retry when retryCondition is true
  ✅ should retry with delay when x-ratelimit-remaining is 0 and retry-after header is present
  ✅ should retry with delay when x-ratelimit-remaining is 0 and x-ratelimit-reset header is present
  ✅ should retry with default delay when x-ratelimit-remaining is 0 and no reset headers are present
  ✅ should reject with rate limit error when x-ratelimit-remaining is 0 and retry limit is exceeded
  ✅ should retry when x-ratelimit-remaining is greater than 0
  ✅ should retry when x-ratelimit-remaining header is not present
  ✅ should successfully retry after rate limit token replenishment using x-ratelimit-reset-time header
  ✅ should handle token replenishment scenario with increasing delay
  ✅ should simulate real-world token bucket replenishment after rate limit exhaustion
  ✅ should handle retry error rejection when rate limited request fails on retry
  ✅ should reject with original error when 429/401 response has no data
  ✅ should create and throw custom error for non-retryable responses
  ✅ should create custom error for 500 internal server error
  ✅ should handle custom error for 422 unprocessable entity
calculateRateLimitDelay
  ✅ should return delay from retry-after header in milliseconds
  ✅ should return delay from x-ratelimit-reset header with Unix timestamp
  ✅ should return minimum delay when x-ratelimit-reset is in the past
  ✅ should return delay from x-ratelimit-reset-time header with ISO string
  ✅ should return minimum delay when x-ratelimit-reset-time is in the past
  ✅ should return default fallback delay when no rate limit headers are present
  ✅ should return default fallback delay when headers have other unrelated values
  ✅ should prioritize retry-after over other headers
  ✅ should prioritize x-ratelimit-reset over x-ratelimit-reset-time when retry-after is not present