You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.2 KiB

import test from 'ava'
import nock from 'nock'
8 years ago
import data from './fixtures/data'
import Onionoo from '../'
8 years ago
test('Onionoo instance contains default endpoints', t => {
const onionoo = new Onionoo()
8 years ago
t.deepEqual(Object.keys(onionoo), data.defaultEndpoints)
})
test('Default endpoint makes correct request', async t => {
const onionoo = new Onionoo()
const defaultEndpoint = data.defaultEndpoints[0]
const scope = nock(data.defaultBaseUrl)
.get(`/${defaultEndpoint}`)
.reply(200, data.dummyResponse)
const response = await onionoo[defaultEndpoint]()
t.deepEqual(response.body, data.dummyResponse)
t.truthy(scope.isDone())
})
test('Can pass in custom endpoint array', t => {
const endpoints = [
'foo',
'bar'
]
const onionoo = new Onionoo({ endpoints })
t.deepEqual(Object.keys(onionoo), endpoints)
})
test('Custom endpoint makes correct request', async t => {
const customEndpoint = 'foo'
const onionoo = new Onionoo({ endpoints: [customEndpoint] })
const scope = nock(data.defaultBaseUrl)
.get(`/${customEndpoint}`)
.reply(200, data.dummyResponse)
const response = await onionoo[customEndpoint]()
t.deepEqual(response.body, data.dummyResponse)
t.truthy(scope.isDone())
})