From eede67bf4eb502e1f9eb587bcc0a13ff7e6f0198 Mon Sep 17 00:00:00 2001 From: Tiaan du Plessis Date: Sun, 18 Mar 2018 22:23:47 +0200 Subject: [PATCH] Fix argument parsing --- index.js | 7 +++++-- test.js | 8 +++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 0b0e9d6..9a3343a 100644 --- a/index.js +++ b/index.js @@ -30,7 +30,9 @@ class CoinMarketCap { * client.getTicker({convert: 'EUR'}).then(console.log).catch(console.error) * client.getTicker({start: 0, limit: 5}).then(console.log).catch(console.error) */ - getTicker ({ start, limit, convert, currency }) { + getTicker (args = {}) { + const { start, limit, convert, currency } = args + return createRequest({ url: `${this.url}/ticker${currency ? `/${currency}/`.toLowerCase() : ''}`, headers: this.headers, @@ -62,7 +64,8 @@ class CoinMarketCap { } } -const createRequest = ({ url, headers, query }) => { +const createRequest = (args = {}) => { + const { url, headers, query } = args const opts = { headers, method: 'GET' diff --git a/test.js b/test.js index 24a20da..8926278 100644 --- a/test.js +++ b/test.js @@ -12,10 +12,12 @@ test('should return new CoinMarketCap client', () => { test('should get latest ticker', async () => { const client = new CoinMarketCap() - const ticker = await client.getTicker({limit: 10}) + const ticker1 = await client.getTicker() + const ticker2 = await client.getTicker({limit: 10}) - expect(typeof ticker).toBe('object') - expect(ticker.length).toBe(10) + expect(typeof ticker1).toBe('object') + expect(typeof ticker2).toBe('object') + expect(ticker2.length).toBe(10) }) test('should get latest global', async () => {