diff options
author | Kevin Serrano <kevgagser@gmail.com> | 2016-08-25 04:58:50 +0800 |
---|---|---|
committer | Kevin Serrano <kevgagser@gmail.com> | 2016-08-25 04:58:50 +0800 |
commit | c82a494b4bc3bd12da52356119698cc380128669 (patch) | |
tree | d556bfcb4541ab8aed2a13dd9e1fa306ad19681a | |
parent | e42b35398bd288a2ce3a93413d0af551dcae2e95 (diff) | |
download | tangerine-wallet-browser-c82a494b4bc3bd12da52356119698cc380128669.tar tangerine-wallet-browser-c82a494b4bc3bd12da52356119698cc380128669.tar.gz tangerine-wallet-browser-c82a494b4bc3bd12da52356119698cc380128669.tar.bz2 tangerine-wallet-browser-c82a494b4bc3bd12da52356119698cc380128669.tar.lz tangerine-wallet-browser-c82a494b4bc3bd12da52356119698cc380128669.tar.xz tangerine-wallet-browser-c82a494b4bc3bd12da52356119698cc380128669.tar.zst tangerine-wallet-browser-c82a494b4bc3bd12da52356119698cc380128669.zip |
Implement usage of nock.
-rw-r--r-- | app/scripts/lib/config-manager.js | 34 | ||||
-rw-r--r-- | package.json | 1 | ||||
-rw-r--r-- | test/unit/config-manager-test.js | 13 |
3 files changed, 24 insertions, 24 deletions
diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js index a37447fa2..715efb42e 100644 --- a/app/scripts/lib/config-manager.js +++ b/app/scripts/lib/config-manager.js @@ -288,29 +288,19 @@ ConfigManager.prototype.getCurrentFiat = function () { return ('fiatCurrency' in data) && data.fiatCurrency } -ConfigManager.prototype.updateConversionRate = function (mock = false, mockCurrency = 'USD') { +ConfigManager.prototype.updateConversionRate = function () { var data = this.getData() - if (!mock) { - return rp(`https://www.cryptonator.com/api/ticker/eth-${data.fiatCurrency}`) - .then((response) => { - const parsedResponse = JSON.parse(response) - this.setConversionPrice(parsedResponse.ticker.price) - this.setConversionDate(parsedResponse.timestamp) - }).catch((err) => { - console.error('Error in conversion.', err) - this.setConversionPrice(0) - this.setConversionDate('N/A') - }) - } else { - return new Promise(function(resolve, reject) { resolve() }).then((response) => { - this.setConversionPrice('11.01') - this.setConversionDate(1472065924) - }).catch((err) => { - console.error('Error in conversion.', err) - this.setConversionPrice('11.01') - this.setConversionDate(1472065924) - }) - } + return rp(`https://www.cryptonator.com/api/ticker/eth-${data.fiatCurrency}`) + .then((response) => { + const parsedResponse = JSON.parse(response) + this.setConversionPrice(parsedResponse.ticker.price) + this.setConversionDate(parsedResponse.timestamp) + }).catch((err) => { + console.error('Error in conversion.', err) + this.setConversionPrice(0) + this.setConversionDate('N/A') + }) + } ConfigManager.prototype.setConversionPrice = function (price) { diff --git a/package.json b/package.json index 57d71e865..774af2b0c 100644 --- a/package.json +++ b/package.json @@ -108,6 +108,7 @@ "mocha-eslint": "^2.1.1", "mocha-jsdom": "^1.1.0", "mocha-sinon": "^1.1.5", + "nock": "^8.0.0", "qs": "^6.2.0", "qunit": "^0.9.1", "sinon": "^1.17.3", diff --git a/test/unit/config-manager-test.js b/test/unit/config-manager-test.js index d4fd1d661..e3c7cb27b 100644 --- a/test/unit/config-manager-test.js +++ b/test/unit/config-manager-test.js @@ -4,6 +4,7 @@ const STORAGE_KEY = 'metamask-persistance-key' var configManagerGen = require('../lib/mock-config-manager') var configManager const rp = require('request-promise') +const nock = require('nock') describe('config-manager', function() { @@ -47,12 +48,15 @@ describe('config-manager', function() { describe('#updateConversionRate', function() { it('should retrieve an update for ETH to USD and set it in memory', function(done) { this.timeout(15000) + var usdMock = nock('https://www.cryptonator.com') + .get('/api/ticker/eth-USD') + .reply(200, '{"ticker":{"base":"ETH","target":"USD","price":"11.02456145","volume":"44948.91745289","change":"-0.01472534"},"timestamp":1472072136,"success":true,"error":""}') assert.equal(configManager.getConversionRate(), false) var promise = new Promise( function (resolve, reject) { configManager.setCurrentFiat('USD') - configManager.updateConversionRate(true, 'USD').then(function() { + configManager.updateConversionRate().then(function() { resolve() }) }) @@ -71,10 +75,15 @@ describe('config-manager', function() { this.timeout(15000) assert.equal(configManager.getConversionRate(), false) + var usdMock = nock('https://www.cryptonator.com') + .get('/api/ticker/eth-JPY') + .reply(200, '{"ticker":{"base":"ETH","target":"JPY","price":"11.02456145","volume":"44948.91745289","change":"-0.01472534"},"timestamp":1472072136,"success":true,"error":""}') + + var promise = new Promise( function (resolve, reject) { configManager.setCurrentFiat('JPY') - configManager.updateConversionRate(true, 'JPY').then(function() { + configManager.updateConversionRate().then(function() { resolve() }) }) |