From bda52f7cba9cd866d2244c402fed2e82e1366005 Mon Sep 17 00:00:00 2001 From: tmashuang Date: Fri, 14 Jul 2017 10:34:03 -0700 Subject: [PATCH 1/4] Infura Network response tests --- app/scripts/controllers/infura.js | 1 + test/unit/infura-controller-test.js | 92 ++++++++++++++++++----------- 2 files changed, 59 insertions(+), 34 deletions(-) diff --git a/app/scripts/controllers/infura.js b/app/scripts/controllers/infura.js index 98375b446..b34b0bc03 100644 --- a/app/scripts/controllers/infura.js +++ b/app/scripts/controllers/infura.js @@ -26,6 +26,7 @@ class InfuraController { this.store.updateState({ infuraNetworkStatus: parsedResponse, }) + return parsedResponse }) } diff --git a/test/unit/infura-controller-test.js b/test/unit/infura-controller-test.js index 912867764..b9050f4c2 100644 --- a/test/unit/infura-controller-test.js +++ b/test/unit/infura-controller-test.js @@ -1,34 +1,58 @@ -// polyfill fetch -// global.fetch = function () {return Promise.resolve({ -// json: () => { return Promise.resolve({"mainnet": "ok", "ropsten": "degraded", "kovan": "down", "rinkeby": "ok"}) }, -// }) -// } -// const assert = require('assert') -// const InfuraController = require('../../app/scripts/controllers/infura') -// -// describe('infura-controller', function () { -// var infuraController -// -// beforeEach(function () { -// infuraController = new InfuraController() -// }) -// -// describe('network status queries', function () { -// describe('#checkInfuraNetworkStatus', function () { -// it('should return an object reflecting the network statuses', function (done) { -// this.timeout(15000) -// infuraController.checkInfuraNetworkStatus() -// .then(() => { -// const networkStatus = infuraController.store.getState().infuraNetworkStatus -// assert.equal(Object.keys(networkStatus).length, 4) -// assert.equal(networkStatus.mainnet, 'ok') -// assert.equal(networkStatus.ropsten, 'degraded') -// assert.equal(networkStatus.kovan, 'down') -// }) -// .then(() => done()) -// .catch(done) -// -// }) -// }) -// }) -// }) +const assert = require('assert') +const InfuraController = require('../../app/scripts/controllers/infura') + +describe('infura-controller', function () { + var infuraController + let response + + before(async function () { + infuraController = new InfuraController() + response = await infuraController.checkInfuraNetworkStatus() + }) + + describe('Network status queries', function () { + it('should return object/json', function () { + assert.equal(typeof response, 'object') + }) + + describe('Mainnet', function () { + it('should have Mainnet', function () { + assert.equal(Object.keys(response)[0], 'mainnet') + }) + + it('should have a value for Mainnet status', function () { + assert(response.mainnet, 'Mainnet status') + }) + }) + + describe('Ropsten', function () { + it('should have Ropsten', function () { + assert.equal(Object.keys(response)[1], 'ropsten') + }) + + it('should have a value for Ropsten status', function () { + assert(response.ropsten, 'Ropsten status') + }) + }) + + describe('Kovan', function () { + it('should have Kovan', function () { + assert.equal(Object.keys(response)[2], 'kovan') + }) + + it('should have a value for Kovan status', function () { + assert(response.kovan, 'Kovan status') + }) + }) + + describe('Rinkeby', function () { + it('should have Rinkeby', function () { + assert.equal(Object.keys(response)[3], 'rinkeby') + }) + + it('should have a value for Rinkeby status', function () { + assert(response.rinkeby, 'Rinkeby status') + }) + }) + }) +}) From 02cf65d513b12f3310c2c42ad1ea87165b663e4d Mon Sep 17 00:00:00 2001 From: tmashuang Date: Fri, 14 Jul 2017 11:50:41 -0700 Subject: [PATCH 2/4] Use Let instead of var --- test/unit/infura-controller-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/infura-controller-test.js b/test/unit/infura-controller-test.js index b9050f4c2..37cdabe3a 100644 --- a/test/unit/infura-controller-test.js +++ b/test/unit/infura-controller-test.js @@ -2,7 +2,7 @@ const assert = require('assert') const InfuraController = require('../../app/scripts/controllers/infura') describe('infura-controller', function () { - var infuraController + let infuraController let response before(async function () { From 6cf2a956c1df56aa7bdc04d94f89752b0c578f87 Mon Sep 17 00:00:00 2001 From: tmashuang Date: Fri, 14 Jul 2017 13:05:56 -0700 Subject: [PATCH 3/4] Update Sinon --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1f2d0d591..e0bb303bf 100644 --- a/package.json +++ b/package.json @@ -176,7 +176,7 @@ "react-addons-test-utils": "^15.5.1", "react-test-renderer": "^15.5.4", "react-testutils-additions": "^15.2.0", - "sinon": "^1.17.3", + "sinon": "^2.3.8", "tape": "^4.5.1", "testem": "^1.10.3", "uglifyify": "^3.0.1", From a4c7d95d0de01a37c1e9debea51eb9e2fd8bc2a7 Mon Sep 17 00:00:00 2001 From: tmashuang Date: Fri, 14 Jul 2017 13:06:42 -0700 Subject: [PATCH 4/4] Sinon stub infura network status --- test/unit/infura-controller-test.js | 32 ++++++++++++++++------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/test/unit/infura-controller-test.js b/test/unit/infura-controller-test.js index 37cdabe3a..605305efa 100644 --- a/test/unit/infura-controller-test.js +++ b/test/unit/infura-controller-test.js @@ -1,57 +1,61 @@ const assert = require('assert') +const sinon = require('sinon') const InfuraController = require('../../app/scripts/controllers/infura') describe('infura-controller', function () { - let infuraController - let response + let infuraController, sandbox, networkStatus + const response = {'mainnet': 'degraded', 'ropsten': 'ok', 'kovan': 'ok', 'rinkeby': 'down'} before(async function () { infuraController = new InfuraController() - response = await infuraController.checkInfuraNetworkStatus() + sandbox = sinon.sandbox.create() + sinon.stub(infuraController, 'checkInfuraNetworkStatus').resolves(response) + networkStatus = await infuraController.checkInfuraNetworkStatus() + }) + + after(function () { + sandbox.restore() }) describe('Network status queries', function () { - it('should return object/json', function () { - assert.equal(typeof response, 'object') - }) describe('Mainnet', function () { it('should have Mainnet', function () { - assert.equal(Object.keys(response)[0], 'mainnet') + assert.equal(Object.keys(networkStatus)[0], 'mainnet') }) it('should have a value for Mainnet status', function () { - assert(response.mainnet, 'Mainnet status') + assert.equal(networkStatus.mainnet, 'degraded') }) }) describe('Ropsten', function () { it('should have Ropsten', function () { - assert.equal(Object.keys(response)[1], 'ropsten') + assert.equal(Object.keys(networkStatus)[1], 'ropsten') }) it('should have a value for Ropsten status', function () { - assert(response.ropsten, 'Ropsten status') + assert.equal(networkStatus.ropsten, 'ok') }) }) describe('Kovan', function () { it('should have Kovan', function () { - assert.equal(Object.keys(response)[2], 'kovan') + assert.equal(Object.keys(networkStatus)[2], 'kovan') }) it('should have a value for Kovan status', function () { - assert(response.kovan, 'Kovan status') + assert.equal(networkStatus.kovan, 'ok') }) }) describe('Rinkeby', function () { it('should have Rinkeby', function () { - assert.equal(Object.keys(response)[3], 'rinkeby') + assert.equal(Object.keys(networkStatus)[3], 'rinkeby') }) it('should have a value for Rinkeby status', function () { - assert(response.rinkeby, 'Rinkeby status') + assert.equal(networkStatus.rinkeby, 'down') }) }) })