From 9fd3f2c017911f73e890b2271001370a61cac01d Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Mon, 22 Jun 2026 17:09:25 -0400 Subject: [PATCH] fix: use query params for GET address-book methods - 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 --- .../src/bitgo/address-book/address-book.ts | 18 ++++- .../unit/bitgo/address-book/address-book.ts | 73 +++++++++++++++++++ 2 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 modules/sdk-core/test/unit/bitgo/address-book/address-book.ts diff --git a/modules/sdk-core/src/bitgo/address-book/address-book.ts b/modules/sdk-core/src/bitgo/address-book/address-book.ts index e578cb9a4e..77053b53ba 100644 --- a/modules/sdk-core/src/bitgo/address-book/address-book.ts +++ b/modules/sdk-core/src/bitgo/address-book/address-book.ts @@ -50,7 +50,11 @@ export class AddressBook implements IAddressBook { */ getConnections(params?: GetAddressBookConnectionsParams): Promise { const url = this.bitgo.microservicesUrl('/api/address-book/v1/connections'); - return this.bitgo.get(url).set('enterprise-id', this.enterpriseId).send(params).result(); + return this.bitgo + .get(url) + .set('enterprise-id', this.enterpriseId) + .query(params ?? {}) + .result(); } /** @@ -125,7 +129,11 @@ export class AddressBook implements IAddressBook { params?: GetAddressBookListingEntryContactsParams ): Promise { const url = this.bitgo.microservicesUrl('/api/address-book/v1/listing/entry/contacts'); - return this.bitgo.get(url).set('enterprise-id', this.enterpriseId).send(params).result(); + return this.bitgo + .get(url) + .set('enterprise-id', this.enterpriseId) + .query(params ?? {}) + .result(); } /** @@ -135,7 +143,11 @@ export class AddressBook implements IAddressBook { params?: GetAddressBookListingEntryDirectoryParams ): Promise { const url = this.bitgo.microservicesUrl('/api/address-book/v1/listing/entry/directory'); - return this.bitgo.get(url).set('enterprise-id', this.enterpriseId).send(params).result(); + return this.bitgo + .get(url) + .set('enterprise-id', this.enterpriseId) + .query(params ?? {}) + .result(); } /** diff --git a/modules/sdk-core/test/unit/bitgo/address-book/address-book.ts b/modules/sdk-core/test/unit/bitgo/address-book/address-book.ts new file mode 100644 index 0000000000..cb41811d32 --- /dev/null +++ b/modules/sdk-core/test/unit/bitgo/address-book/address-book.ts @@ -0,0 +1,73 @@ +import * as sinon from 'sinon'; +import 'should'; +import { AddressBook } from '../../../../src/bitgo/address-book/address-book'; + +describe('AddressBook', function () { + let addressBook: AddressBook; + let mockBitGo: any; + const enterpriseId = 'test-enterprise-id'; + + function makeGetStub() { + const queryStub = sinon.stub().returns({ result: sinon.stub().resolves({}) }); + const setStub = sinon.stub().returns({ query: queryStub }); + mockBitGo.get.returns({ set: setStub }); + return { setStub, queryStub }; + } + + beforeEach(function () { + mockBitGo = { + get: sinon.stub(), + microservicesUrl: sinon.stub().callsFake((path: string) => `https://app.bitgo.com${path}`), + }; + addressBook = new AddressBook(enterpriseId, mockBitGo); + }); + + afterEach(function () { + sinon.restore(); + }); + + describe('getConnections', function () { + it('should pass params as query string, not request body', async function () { + const { queryStub } = makeGetStub(); + const params = { connectionType: 'DVP' as const, status: 'INACTIVE' as const, offset: 0, limit: 10 }; + + await addressBook.getConnections(params); + + sinon.assert.calledOnce(queryStub); + sinon.assert.calledWith(queryStub, params); + }); + + it('should work with no params', async function () { + const { queryStub } = makeGetStub(); + + await addressBook.getConnections(); + + sinon.assert.calledOnce(queryStub); + sinon.assert.calledWith(queryStub, {}); + }); + }); + + describe('getListingEntryContacts', function () { + it('should pass params as query string, not request body', async function () { + const { queryStub } = makeGetStub(); + const params = { status: 'ACTIVE' as const, limit: 5 }; + + await addressBook.getListingEntryContacts(params); + + sinon.assert.calledOnce(queryStub); + sinon.assert.calledWith(queryStub, params); + }); + }); + + describe('getListingEntryDirectory', function () { + it('should pass params as query string, not request body', async function () { + const { queryStub } = makeGetStub(); + const params = { status: 'ACTIVE' as const, limit: 5 }; + + await addressBook.getListingEntryDirectory(params); + + sinon.assert.calledOnce(queryStub); + sinon.assert.calledWith(queryStub, params); + }); + }); +});