Skip to content

Commit

Permalink
Fix argument parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
tiaanduplessis committed Mar 18, 2018
1 parent 9120e06 commit eede67b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 5 additions & 2 deletions index.js
Expand Up @@ -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,
Expand Down Expand Up @@ -62,7 +64,8 @@ class CoinMarketCap {
}
}

const createRequest = ({ url, headers, query }) => {
const createRequest = (args = {}) => {
const { url, headers, query } = args
const opts = {
headers,
method: 'GET'
Expand Down
8 changes: 5 additions & 3 deletions test.js
Expand Up @@ -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 () => {
Expand Down

0 comments on commit eede67b

Please sign in to comment.