Skip to content

chore: Add docs and tests for sending custom headers#262

Merged
jimmyjames merged 1 commit into
mainfrom
chore/custom-header-docs-and-tests
Oct 3, 2025
Merged

chore: Add docs and tests for sending custom headers#262
jimmyjames merged 1 commit into
mainfrom
chore/custom-header-docs-and-tests

Conversation

@jimmyjames

@jimmyjames jimmyjames commented Oct 3, 2025

Copy link
Copy Markdown
Contributor

This PR adds documentation and testing for custom header functionality in the OpenFGA JavaScript SDK.

Description

What problem is being solved?

SDK is missing documentation and tests for sending custom HTTP headers.

How is it being solved?

Updating documentation and adding unit tests.

What changes are made to solve it?

  • Added a new "Custom Headers" section to the README with examples for both default headers (via baseOptions) and per-request headers
  • Created test suite (tests/headers.test.ts) with 19 test cases covering all header scenarios including:
    • Default headers from client configuration
    • Per-request headers and precedence behavior
    • Header merging and override behavior
    • Content-Type header protection behavior
    • Edge cases and special scenarios

In addition to unit testing, manual testing was also done:

  • verified client headers being sent
  • verified per-request headers being sent
  • verified per-request headers override client headers

References

Review Checklist

  • I have clicked on "allow edits by maintainers".
  • I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • The correct base branch is being used, if not main
  • I have added tests to validate that the change in functionality is working as expected

Summary by CodeRabbit

  • Documentation

    • Expanded guidance on Custom Headers: how to set default/global headers during client setup and override them per request, with examples. Clarifies header precedence and that Content-Type defaults to application/json unless overridden.
  • Tests

    • Added comprehensive test coverage for header handling across client operations, validating default vs per-request merge and precedence, case-insensitive behavior, Content-Type protections, and various edge cases (empty/undefined options, special characters, large header sets).

@jimmyjames
jimmyjames requested review from a team as code owners October 3, 2025 17:51
@coderabbitai

coderabbitai Bot commented Oct 3, 2025

Copy link
Copy Markdown

Walkthrough

Adds README documentation for default and per-request custom headers. Introduces a new test file validating header behavior (defaults, overrides, merging, case-insensitivity, Content-Type handling, edge cases) across multiple client methods. No runtime or public API changes.

Changes

Cohort / File(s) Summary of Changes
Documentation
README.md
Added sections describing default headers via baseOptions.headers and per-request header overrides with examples.
Tests
tests/headers.test.ts
New test suite covering default/per-request headers, merge/precedence rules, case-insensitivity, Content-Type defaults/overrides, edge cases (empty/undefined options, large header sets, special values), and consistency across check/read/write methods.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title accurately and succinctly describes the main change by indicating that documentation and tests for sending custom headers are being added; it matches the updates in both the README and the new test suite without extraneous details.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/custom-header-docs-and-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.41%. Comparing base (8c6b8f0) to head (cc56563).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #262      +/-   ##
==========================================
+ Coverage   88.16%   88.41%   +0.24%     
==========================================
  Files          23       23              
  Lines        1217     1217              
  Branches      197      216      +19     
==========================================
+ Hits         1073     1076       +3     
+ Misses         86       85       -1     
+ Partials       58       56       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread tests/headers.test.ts
Comment thread tests/headers.test.ts
@jimmyjames
jimmyjames added this pull request to the merge queue Oct 3, 2025
Merged via the queue into main with commit b2a565b Oct 3, 2025
21 checks passed
@jimmyjames
jimmyjames deleted the chore/custom-header-docs-and-tests branch October 3, 2025 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants