Browse Source

Test HTML responses for errors

pull/15/head
Luke Childs 8 years ago
parent
commit
88fb9715e7
  1. 21
      test/errors.js
  2. 3
      test/fixtures/data.js

21
test/errors.js

@ -0,0 +1,21 @@
import test from 'ava'
import nock from 'nock'
import data from './fixtures/data'
import Onionoo from '../'
test('Handle HTML responses for errors', async t => {
const onionoo = new Onionoo()
const defaultEndpoint = data.defaultEndpoints[0]
const scope = nock(data.defaultBaseUrl)
.get(`/${defaultEndpoint}`)
.reply(400, data.dummy400Response)
try {
await onionoo[defaultEndpoint]()
} catch (e) {
t.deepEqual(e.response.body, data.dummy400Response)
}
t.truthy(scope.isDone())
})

3
test/fixtures/data.js

@ -23,5 +23,6 @@ module.exports = {
],
bridges_published: '2016-12-22 04:41:03',
bridges: []
}
},
dummy400Response: '<html>\n<head>\n<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>\n<title>Error 400 Bad Request</title>\n</head>\n<body><h2>HTTP ERROR 400</h2>\n<p>Problem accessing /summary. Reason:\n<pre> Bad Request</pre></p><hr /><i><small>Powered by Jetty://</small></i><br/> \n<br/> \n<br/> \n<br/> \n<br/> \n<br/> \n<br/> \n<br/> \n<br/> \n<br/> \n<br/> \n<br/> \n<br/> \n<br/> \n<br/> \n<br/> \n<br/> \n<br/> \n<br/> \n<br/> \n\n</body>\n</html>'
}

Loading…
Cancel
Save