Skip to content

Conversation

Copy link

Copilot AI commented Sep 4, 2025

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

  • Add headers support to HttpClient constructor and methods
  • Update entry point to pass headers from configuration to HttpClient
  • Add TypeScript interface definition for headers
  • Add comprehensive test suite for headers functionality
  • Update existing tests to include headers parameter
  • Add header verification tests for AtlasSearch methods
  • Ensure all tests pass with 100% code coverage
  • 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/fetchStream methods to properly merge default headers with method-specific headers
  • Entry Point: Updated getMongodbAtlasApiClient to pass headers from configuration to HttpClient
  • TypeScript: Added headers?: Record<string, string> to AtlasClientConfig interface
  • Header Merging: Custom headers are merged with method-specific headers (like Content-Type) and httpOptions headers, 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.

Copy link
Author

Copilot AI commented Sep 4, 2025

@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.

Co-authored-by: montumodi <12596663+montumodi@users.noreply.github.com>
Copilot AI changed the title [WIP] MongoDB Atlas Administration API V2 - Support for Headers Add headers support for MongoDB Atlas API v2 compatibility Sep 4, 2025
Copilot AI requested a review from montumodi September 4, 2025 11:45
Copilot finished work on behalf of montumodi September 4, 2025 11:45
const requestParams = {"digestAuth": "dummyPublicKey:dummyPrivateKey", "dataType": "json"};
const requestParams = {"digestAuth": "dummyPublicKey:dummyPrivateKey", "dataType": "json", "headers": {}};
await atlasSearch.get("clusterName", "indexId", {"queryStringParam1": "value1", "httpOptions": {"options1": "value1"}});
expect(mockRequest.request.calledWith("dummyBaseUrl/groups/dummyProjectId/clusters/clusterName/fts/indexes/indexId?queryStringParam1=value1", {...requestParams, "options1": "value1"})).to.be.true();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot shouldn't there be a check that headers are being passed correctly?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're absolutely right! I've added tests to verify that headers are being passed correctly when using AtlasSearch methods:

  1. Integration test: Verifies that custom headers configured on the client are included in actual HTTP requests made by AtlasSearch methods
  2. Unit test: Verifies that custom headers are properly passed to the underlying request mechanism

The tests ensure that when a client is configured with custom headers (like "Accept": "application/vnd.atlas.2025-03-12+json"), those headers are correctly propagated through AtlasSearch method calls.

Commit: 1105829

Co-authored-by: montumodi <12596663+montumodi@users.noreply.github.com>
Copilot AI requested a review from montumodi September 4, 2025 11:55
Copilot finished work on behalf of montumodi September 4, 2025 11:55
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.

MongoDB Atlas Administration API V2 - Support for Headers

2 participants