-
Notifications
You must be signed in to change notification settings - Fork 303
fix: use query params for GET address-book methods #9084
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,7 +50,11 @@ export class AddressBook implements IAddressBook { | |
| */ | ||
| getConnections(params?: GetAddressBookConnectionsParams): Promise<GetAddressBookConnectionsResponse> { | ||
| 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 ?? {}) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: |
||
| .result(); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -125,7 +129,11 @@ export class AddressBook implements IAddressBook { | |
| params?: GetAddressBookListingEntryContactsParams | ||
| ): Promise<GetAddressBookListingEntryContactsResponse> { | ||
| 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<GetAddressBookListingEntryDirectoryResponse> { | ||
| 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(); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Low: sinon.assert.calledWith(mockBitGo.get, 'https://app.bitgo.com/api/address-book/v1/connections'); |
||
| 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); | ||
| }); | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Low: it('should work with no params', async function () {
const { queryStub } = makeGetStub();
await addressBook.getListingEntryContacts();
sinon.assert.calledWith(queryStub, {});
}); |
||
|
|
||
| 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); | ||
| }); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
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.