Skip to content

fix: use query params for GET address-book methods#9084

Open
seanchen0818 wants to merge 1 commit into
masterfrom
GN-2899-sdk-getconnections-query-params
Open

fix: use query params for GET address-book methods#9084
seanchen0818 wants to merge 1 commit into
masterfrom
GN-2899-sdk-getconnections-query-params

Conversation

@seanchen0818

Copy link
Copy Markdown

Summary

  • getConnections, getListingEntryContacts, and getListingEntryDirectory were using .send(params) on GET requests, which puts params in the request body — ignored by the server
  • Replaced with .query(params) so filters are correctly sent as URL query params
  • Confirmed against address-book service SDK spec: all three routes define filters under query:, not body:

Test plan

  • Added unit tests for all three GET methods verifying .query() is called with the provided params
  • All 4 tests pass locally

Fixes GN-2899

🤖 Generated with Claude Code

@seanchen0818 seanchen0818 requested review from a team as code owners June 22, 2026 21:14
@linear-code

linear-code Bot commented Jun 22, 2026

Copy link
Copy Markdown

GN-2899

seanchen0818 added a commit that referenced this pull request Jun 22, 2026
- Replace .send(params) with .query(params) in getConnections,
  getListingEntryContacts, and getListingEntryDirectory so filters
  are sent as URL query params rather than request body

GN-2899 #9084
@seanchen0818 seanchen0818 force-pushed the GN-2899-sdk-getconnections-query-params branch from c2e224f to f8046c6 Compare June 22, 2026 21:16
@pranishnepal

Copy link
Copy Markdown
Contributor

Tests failing

seanchen0818 added a commit that referenced this pull request Jun 22, 2026
- Replace .send(params) with .query(params) in getConnections,
  getListingEntryContacts, and getListingEntryDirectory so filters
  are sent as URL query params rather than request body

GN-2899 #9084
@seanchen0818 seanchen0818 force-pushed the GN-2899-sdk-getconnections-query-params branch from f8046c6 to 1b395d7 Compare June 22, 2026 21:39
seanchen0818 added a commit that referenced this pull request Jun 22, 2026
- Replace .send(params) with .query(params) in getConnections,
  getListingEntryContacts, and getListingEntryDirectory so filters
  are sent as URL query params rather than request body

GN-2899 #9084
@seanchen0818 seanchen0818 force-pushed the GN-2899-sdk-getconnections-query-params branch from 1b395d7 to e3b92e2 Compare June 22, 2026 21:57
seanchen0818 added a commit that referenced this pull request Jun 22, 2026
- Replace .send(params) with .query(params) in getConnections,
  getListingEntryContacts, and getListingEntryDirectory so filters
  are sent as URL query params rather than request body

GN-2899 #9084
@seanchen0818 seanchen0818 force-pushed the GN-2899-sdk-getconnections-query-params branch from e3b92e2 to 6ad97d5 Compare June 22, 2026 22:01
seanchen0818 added a commit that referenced this pull request Jun 22, 2026
- Replace .send(params) with .query(params) in getConnections,
  getListingEntryContacts, and getListingEntryDirectory so filters
  are sent as URL query params rather than request body

GN-2899 #9084
@seanchen0818 seanchen0818 force-pushed the GN-2899-sdk-getconnections-query-params branch from 6ad97d5 to 9fd3f2c Compare June 22, 2026 22:08

@lokesh-bitgo lokesh-bitgo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The core fix is correct — .send(params) on GET was silently dropping all filter params since most servers ignore the request body on GET requests. .query(params ?? {}) is the right approach. CI is green and the logic is sound.

Leaving a few non-blocking suggestions inline.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit (follow-up): getListing() (line ~82) also calls .send() on a GET with no arguments — same anti-pattern as the methods fixed here. Less harmful since there are no params to drop, but it's inconsistent in the same class. Consider cleaning it up in a follow-up: just remove the .send() call entirely since .get().set(...).result() is sufficient for a parameterless GET.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

updated!

function makeGetStub() {
const queryStub = sinon.stub().returns({ result: sinon.stub().resolves({}) });
const setStub = sinon.stub().returns({ query: queryStub });
mockBitGo.get.returns({ set: setStub });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Low: mockBitGo.get is stubbed to accept any URL — a typo in the endpoint path (e.g. /connections/connection) would go undetected. Consider asserting the URL too:

sinon.assert.calledWith(mockBitGo.get, 'https://app.bitgo.com/api/address-book/v1/connections');

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

updated!

sinon.assert.calledOnce(queryStub);
sinon.assert.calledWith(queryStub, params);
});
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Low: getConnections has a no-params test verifying undefined → {} (the ?? {} path), but getListingEntryContacts and getListingEntryDirectory only have one test each (with params). Consider adding a no-params case for both:

it('should work with no params', async function () {
  const { queryStub } = makeGetStub();
  await addressBook.getListingEntryContacts();
  sinon.assert.calledWith(queryStub, {});
});

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

updated!

return this.bitgo
.get(url)
.set('enterprise-id', this.enterpriseId)
.query(params ?? {})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: GetAddressBookConnectionsParams includes array fields (ownerWalletId?: string[], targetWalletId?: string[]). Superagent's default .query() serializes arrays as repeated keys — ?ownerWalletId=a&ownerWalletId=b. Worth verifying the address-book service parses that format (vs bracket notation ownerWalletId[]=a or comma-separated). If the format doesn't match, these filters would silently not work.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

updated!

- Replace .send(params) with .query(params) in getConnections,
  getListingEntryContacts, and getListingEntryDirectory so filters
  are sent as URL query params rather than request body

GN-2899 #9084
@seanchen0818 seanchen0818 force-pushed the GN-2899-sdk-getconnections-query-params branch from 6c6b2fa to 3fe461e Compare June 23, 2026 15:17
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