api-js icon indicating copy to clipboard operation
api-js copied to clipboard

Ensure SDK matches live API behaviour and broaden coverage

Open basit3407 opened this issue 1 year ago • 2 comments

  • expand Vitest suite to cover client config, fetcher auth flow, retry helper, search defaults, and URL serialization (including fields params fix)
  • add tooling/live-smoke.mjs to fetch a real OAuth token and probe chapters, verses, resources, audio, and search against the Quran Foundation API, logging payload snippets on failure
  • wire test setup to shim btoa so Node runs mimic browser envs and keep serialization accurate for production headers

Tests

  • pnpm --filter @quranjs/api test
  • pnpm --filter @quranjs/api test:coverage
  • node tooling/live-smoke.mjs

Summary by CodeRabbit

  • Bug Fixes
    • Fixed query parameter handling for word and translation field filters in API requests, ensuring fields-specific processing now correctly triggers for word_fields and translation_fields parameters.

basit3407 avatar Oct 20 '25 08:10 basit3407

@basit3407 is attempting to deploy a commit to the Ahmed Riad Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Oct 20 '25 08:10 vercel[bot]

Walkthrough

This PR adds .env to gitignore, fixes parameter key naming in URL handling from camelCase to snake_case, introduces comprehensive test coverage for API client, fetcher, search, and URL utilities, adds a btoa polyfill for test compatibility, and implements a live smoke test script for validating API endpoints.

Changes

Cohort / File(s) Summary
Configuration
.gitignore
Added .env entry to ignore environment variable files.
Source Code
packages/api/src/lib/url.ts
Updated parameter key set for special fields handling from camelCase (wordFields, translationFields) to snake_case (word_fields, translation_fields) to align with decamelized keys, enabling fields processing to trigger correctly.
Test Suite
packages/api/test/client.test.ts, packages/api/test/fetcher.test.ts, packages/api/test/retry.test.ts, packages/api/test/search.test.ts, packages/api/test/url.test.ts
Added five new test files validating QuranClient configuration handling, QuranFetcher token caching and request construction, retry helper with error propagation, QuranSearch API option merging, and URL utility functions for parameter serialization.
Test Infrastructure
packages/api/test/setup.ts
Added runtime guard to polyfill globalThis.btoa using Buffer for test environment compatibility.
QA Tooling
tooling/live-smoke.mjs
Introduced live smoke test script that loads environment credentials, validates OAuth token retrieval, and performs endpoint checks against Quran Foundation API with structured payload verification and error reporting.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

The PR includes a single logic fix with medium complexity (parameter naming alignment), five homogeneous new test files following consistent patterns, infrastructure setup, and a new QA script. While the test additions are voluminous, their repetitive and straightforward nature moderates review effort; the parameter fix requires verification of correctness against actual usage.

Poem

🐰 A rabbit hops through tests with glee,
Smoke signals rise, the code runs free,
With snake_case keys and tokens cached,
Environment guarded, bugs all smashed,
Quality blooms where new tests play! 🌱

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "Ensure SDK matches live API behaviour and broaden coverage" is directly related to the changeset. The primary changes include expanding the Vitest suite with multiple new test files (client.test.ts, fetcher.test.ts, retry.test.ts, search.test.ts, url.test.ts), adding a live smoke test script (tooling/live-smoke.mjs) that validates against real Quran Foundation API endpoints, and fixing URL parameter serialization to align with API expectations. The title accurately captures both main aspects: verifying API compatibility and expanding test coverage. While the term "broaden coverage" could be slightly more specific, it is sufficiently clear and not vague or misleading.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Oct 20 '25 08:10 coderabbitai[bot]