From ca5e52920d5fd8388fc1f62f0a98908adfc69c08 Mon Sep 17 00:00:00 2001 From: fragosti Date: Wed, 15 Aug 2018 17:52:13 -0700 Subject: Add fee recipients test --- packages/connect/src/http_client.ts | 10 ++++++--- packages/connect/src/types.ts | 2 +- packages/connect/test/http_client_test.ts | 24 ++++++++++++++++++++++ .../relayer_api_fee_recipients_response_schema.ts | 8 +++++++- 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts index 35d7ee77e..5aeba19dd 100644 --- a/packages/connect/src/http_client.ts +++ b/packages/connect/src/http_client.ts @@ -140,10 +140,14 @@ export class HttpClient implements Client { /** * Retrieve the list of fee recipient addresses used by */ - public async getFeeRecipientsAsync(): Promise { - return this._requestAsync('/fee_recipients', HttpRequestType.Get); + public async getFeeRecipientsAsync(requestOpts?: PagedRequestOpts): Promise { + if (!_.isUndefined(requestOpts)) { + assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema); + } + const feeRecipients = await this._requestAsync('/fee_recipients', HttpRequestType.Get); + assert.doesConformToSchema('feeRecipients', feeRecipients, schemas.relayerApiFeeRecipientsResponseSchema); + return feeRecipients; } - /** * Submit a signed order to the API * @param signedOrder A SignedOrder instance to submit diff --git a/packages/connect/src/types.ts b/packages/connect/src/types.ts index 42417f709..44ea4abd6 100644 --- a/packages/connect/src/types.ts +++ b/packages/connect/src/types.ts @@ -7,7 +7,7 @@ export interface Client { getOrderAsync: (orderHash: string) => Promise; getOrderbookAsync: (request: OrderbookRequest, requestOpts?: PagedRequestOpts) => Promise; getOrderConfigAsync: (request: OrderConfigRequest) => Promise; - getFeeRecipientsAsync: () => Promise; + getFeeRecipientsAsync: (requestOpts?: PagedRequestOpts) => Promise; submitOrderAsync: (signedOrder: SignedOrder) => Promise; } diff --git a/packages/connect/test/http_client_test.ts b/packages/connect/test/http_client_test.ts index 6d5ab288a..cdff00a61 100644 --- a/packages/connect/test/http_client_test.ts +++ b/packages/connect/test/http_client_test.ts @@ -17,6 +17,8 @@ import { orderbookResponse } from './fixtures/standard_relayer_api/orderbook'; import * as orderbookJSON from './fixtures/standard_relayer_api/orderbook.json'; import { ordersResponse } from './fixtures/standard_relayer_api/orders'; import * as ordersResponseJSON from './fixtures/standard_relayer_api/orders.json'; +import { feeRecipientsResponse } from './fixtures/standard_relayer_api/fee_recipients'; +import * as feeRecipientsResponseJSON from './fixtures/standard_relayer_api/fee_recipients.json'; chai.config.includeStack = true; chai.use(dirtyChai); @@ -164,4 +166,26 @@ describe('HttpClient', () => { expect(relayerClient.getOrderConfigAsync(request)).to.be.rejected(); }); }); + describe('#getFeeRecipientsAsync', () => { + const url = `${relayUrl}/fee_recipients`; + it('gets orderbook with default page options when none are provided', async () => { + fetchMock.get(url, feeRecipientsResponseJSON); + const feeRecipients = await relayerClient.getFeeRecipientsAsync(); + expect(feeRecipients).to.be.deep.equal(feeRecipientsResponse); + }); + it('gets orderbook with specified page options', async () => { + const urlWithQuery = `${url}?&page=3&perPage=50`; + fetchMock.get(url, feeRecipientsResponseJSON); + const pagedRequestOptions = { + page: 3, + perPage: 50, + }; + const feeRecipients = await relayerClient.getFeeRecipientsAsync(pagedRequestOptions); + expect(feeRecipients).to.be.deep.equal(feeRecipientsResponse); + }); + it('throws an error for invalid JSON response', async () => { + fetchMock.get(url, { test: 'dummy' }); + expect(relayerClient.getFeeRecipientsAsync()).to.be.rejected(); + }); + }); }); diff --git a/packages/json-schemas/schemas/relayer_api_fee_recipients_response_schema.ts b/packages/json-schemas/schemas/relayer_api_fee_recipients_response_schema.ts index 84d39eb20..150f07af4 100644 --- a/packages/json-schemas/schemas/relayer_api_fee_recipients_response_schema.ts +++ b/packages/json-schemas/schemas/relayer_api_fee_recipients_response_schema.ts @@ -5,9 +5,15 @@ export const relayerApiFeeRecipientsResponseSchema = { { $ref: '/paginatedCollectionSchema' }, { properties: { - records: { $ref: '/addressSchema' }, + records: { $ref: '/relayerApiFeeRecipientsSchema' }, }, required: ['records'], }, ], }; + +export const relayerApiFeeRecipientsSchema = { + id: '/relayerApiFeeRecipientsSchema', + type: 'array', + items: { $ref: '/addressSchema' }, +}; -- cgit v1.2.3