From 88fb9715e752f87247f2af1425be683571a28d45 Mon Sep 17 00:00:00 2001
From: Luke Childs
Date: Fri, 23 Dec 2016 15:35:16 +0700
Subject: [PATCH] Test HTML responses for errors
---
test/errors.js | 21 +++++++++++++++++++++
test/fixtures/data.js | 3 ++-
2 files changed, 23 insertions(+), 1 deletion(-)
create mode 100644 test/errors.js
diff --git a/test/errors.js b/test/errors.js
new file mode 100644
index 0000000..c73b286
--- /dev/null
+++ b/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())
+})
diff --git a/test/fixtures/data.js b/test/fixtures/data.js
index 8b6eb37..37eceea 100644
--- a/test/fixtures/data.js
+++ b/test/fixtures/data.js
@@ -23,5 +23,6 @@ module.exports = {
],
bridges_published: '2016-12-22 04:41:03',
bridges: []
- }
+ },
+ dummy400Response: '\n\n\nError 400 Bad Request\n\nHTTP ERROR 400
\nProblem accessing /summary. Reason:\n
Bad Request
Powered by Jetty://
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n\n\n'
}