From af5d44c278f2d747b22b9238af484a26ba521c50 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Wed, 31 Mar 2021 05:04:35 -0700 Subject: [PATCH] fix(route-utils): Adding unit tests for route-utils --- src/util/route-utils.js | 2 +- test/v4/route-utils.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 test/v4/route-utils.js diff --git a/src/util/route-utils.js b/src/util/route-utils.js index f297469..ba32ca1 100644 --- a/src/util/route-utils.js +++ b/src/util/route-utils.js @@ -156,7 +156,7 @@ class RouteUtils { // Handle 429 errors thrown by nginx if (err.error) { - // console.log('decodeError: err: ', err) + console.log('decodeError: err: ', err) if (err.error.includes('429 Too Many Requests')) { const internalMsg = diff --git a/test/v4/route-utils.js b/test/v4/route-utils.js new file mode 100644 index 0000000..ba25cfd --- /dev/null +++ b/test/v4/route-utils.js @@ -0,0 +1,34 @@ +/* + Unit tests for the route-utils.js library. +*/ + +const assert = require('chai').assert + +const RouteUtils = require('../../src/util/route-utils.js') + +describe('#route-utils', () => { + let uut + + beforeEach(() => { + uut = new RouteUtils() + }) + + describe('#decodeError', () => { + it('should decode a 429 error from nginx', () => { + const err = { + error: '\r\n429 Too Many Requests\r\n\r\n

429 Too Many Requests

\r\n
nginx/1.18.0 (Ubuntu)
\r\n\r\n\r\n', + level: 'error', + message: 'Error in slp.js/hydrateUtxos().', + timestamp: '2021-03-31T04:13:36.662Z' + } + + const result = uut.decodeError(err) + // console.log('result: ', result) + + assert.property(result, 'msg') + assert.equal(result.msg, '429 Too Many Requests') + assert.property(result, 'status') + assert.equal(result.status, 429) + }) + }) +})