Add headers support for MongoDB Atlas API v2 compatibility
This PR adds support for custom headers in the MongoDB Atlas API client to enable compatibility with the new MongoDB Atlas Administration API v2.
Progress Checklist
- [x] Add headers support to HttpClient constructor and methods
- [x] Update entry point to pass headers from configuration to HttpClient
- [x] Add TypeScript interface definition for headers
- [x] Add comprehensive test suite for headers functionality
- [x] Update existing tests to include headers parameter
- [x] Add header verification tests for AtlasSearch methods
- [x] Ensure all tests pass with 100% code coverage
- [x] Address code review feedback
Recent Changes
Added specific tests to verify that custom headers are properly passed through when using AtlasSearch methods:
- Integration test showing headers are included in actual HTTP requests
- Unit test verifying headers are passed to underlying request calls
Implementation Details
- HttpClient: Modified constructor to accept optional headers parameter and updated
fetch/fetchStreammethods to properly merge default headers with method-specific headers - Entry Point: Updated
getMongodbAtlasApiClientto pass headers from configuration to HttpClient - TypeScript: Added
headers?: Record<string, string>toAtlasClientConfiginterface - Header Merging: Custom headers are merged with method-specific headers (like
Content-Type) andhttpOptionsheaders, with method-specific headers taking precedence
Testing
Added comprehensive test suite covering:
- Default header inclusion in requests
- Header merging with method-specific headers
- Header merging with httpOptions headers
- Backward compatibility (works without headers parameter)
- Edge cases with empty headers
- AtlasSearch-specific header verification
All tests pass with 100% code coverage maintained.
Fixes #58.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.
@montumodi 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.
I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.
@copilot I have added copilot instructions in main branch, may be merge main to this branch and redo everything as utillizing that instructions file.
@copilot I have added copilot instructions in main branch, may be merge main to this branch and redo everything as utillizing that instructions file.
I've merged the master branch containing the copilot instructions and verified that the existing implementation already follows all the guidelines specified in .github/copilot-instructions.md.
The headers support implementation:
- Follows established code patterns (private properties with underscore, consistent class structure)
- Test suite follows the documented test framework pattern with MockAgent
- Maintains 100% code coverage
- Passes all linting rules
- Is backward compatible with no breaking changes
- Makes minimal, surgical changes to the codebase
All tests pass successfully, code review found no issues, and the security scan shows no vulnerabilities. Commit: 0350b54