2018-08-10 12:49:26 +02:00
|
|
|
// Copyright BigchainDB GmbH and BigchainDB contributors
|
|
|
|
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
|
|
|
// Code is Apache-2.0 and docs are CC-BY-4.0
|
|
|
|
|
2018-07-19 10:18:49 +02:00
|
|
|
import test from 'ava'
|
2018-08-30 12:26:14 +02:00
|
|
|
import rewire from 'rewire'
|
|
|
|
|
|
|
|
const baseRequestFile = rewire('../../src/baseRequest.js')
|
|
|
|
const baseRequest = baseRequestFile.__get__('baseRequest')
|
|
|
|
const handleResponse = baseRequestFile.__get__('handleResponse')
|
|
|
|
|
|
|
|
test('HandleResponse does not throw error for response ok', t => {
|
|
|
|
const testObj = {
|
|
|
|
ok: true
|
|
|
|
}
|
|
|
|
const expected = testObj
|
|
|
|
const actual = handleResponse(testObj)
|
|
|
|
|
|
|
|
t.deepEqual(actual, expected)
|
|
|
|
})
|
2018-07-19 10:18:49 +02:00
|
|
|
|
|
|
|
test('baseRequest test query and vsprint', async t => {
|
2021-03-09 10:57:37 +01:00
|
|
|
const error = await t.throwsAsync(baseRequest('https://%s.com/', {
|
2018-07-19 10:18:49 +02:00
|
|
|
urlTemplateSpec: ['google'],
|
|
|
|
query: 'teapot'
|
2021-03-09 10:57:37 +01:00
|
|
|
}), { instanceOf: Error, message: 'HTTP Error: Requested page not reachable' })
|
|
|
|
|
|
|
|
t.is(error.requestURI, 'https://www.google.com/teapot')
|
|
|
|
t.is(error.status, '418 I\'m a Teapot')
|
2018-07-19 10:18:49 +02:00
|
|
|
})
|