Add fee recipients test

This commit is contained in:
fragosti
2018-08-15 17:52:13 -07:00
parent 30dfb7511d
commit ca5e52920d
4 changed files with 39 additions and 5 deletions

View File

@@ -140,10 +140,14 @@ export class HttpClient implements Client {
/**
* Retrieve the list of fee recipient addresses used by
*/
public async getFeeRecipientsAsync(): Promise<FeeRecipientsResponse> {
return this._requestAsync('/fee_recipients', HttpRequestType.Get);
public async getFeeRecipientsAsync(requestOpts?: PagedRequestOpts): Promise<FeeRecipientsResponse> {
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

View File

@@ -7,7 +7,7 @@ export interface Client {
getOrderAsync: (orderHash: string) => Promise<APIOrder>;
getOrderbookAsync: (request: OrderbookRequest, requestOpts?: PagedRequestOpts) => Promise<OrderbookResponse>;
getOrderConfigAsync: (request: OrderConfigRequest) => Promise<OrderConfigResponse>;
getFeeRecipientsAsync: () => Promise<FeeRecipientsResponse>;
getFeeRecipientsAsync: (requestOpts?: PagedRequestOpts) => Promise<FeeRecipientsResponse>;
submitOrderAsync: (signedOrder: SignedOrder) => Promise<void>;
}

View File

@@ -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();
});
});
});