diff options
Diffstat (limited to 'test/unit/config-manager-test.js')
-rw-r--r-- | test/unit/config-manager-test.js | 77 |
1 files changed, 76 insertions, 1 deletions
diff --git a/test/unit/config-manager-test.js b/test/unit/config-manager-test.js index 8974a6bc5..b34089163 100644 --- a/test/unit/config-manager-test.js +++ b/test/unit/config-manager-test.js @@ -3,6 +3,7 @@ const extend = require('xtend') const STORAGE_KEY = 'metamask-persistance-key' var configManagerGen = require('../lib/mock-config-manager') var configManager +const rp = require('request-promise') describe('config-manager', function() { @@ -11,6 +12,81 @@ describe('config-manager', function() { configManager = configManagerGen() }) + describe('currency conversions', function() { + + describe('#getCurrentFiat', function() { + it('should return false if no previous key exists', function() { + var result = configManager.getCurrentFiat() + assert.ok(!result) + }) + }) + + describe('#setCurrentFiat', function() { + it('should make getCurrentFiat return true once set', function() { + assert.equal(configManager.getCurrentFiat(), false) + configManager.setCurrentFiat('USD') + var result = configManager.getCurrentFiat() + assert.equal(result, 'USD') + }) + + it('should work with other currencies as well', function() { + assert.equal(configManager.getCurrentFiat(), false) + configManager.setCurrentFiat('JPY') + var result = configManager.getCurrentFiat() + assert.equal(result, 'JPY') + }) + }) + + describe('#getConversionRate', function() { + it('should return false if non-existent', function() { + var result = configManager.getConversionRate() + assert.ok(!result) + }) + }) + + describe('#updateConversionRate', function() { + it('should retrieve an update for ETH to USD and set it in memory', function(done) { + this.timeout(15000) + assert.equal(configManager.getConversionRate(), false) + var promise = new Promise( + function (resolve, reject) { + configManager.setCurrentFiat('USD') + configManager.updateConversionRate().then(function() { + resolve() + }) + }) + + promise.then(function() { + var result = configManager.getConversionRate() + assert.equal(typeof result, 'number') + done() + }).catch(function(err) { + console.log(err) + }) + + }) + + it('should work for JPY as well.', function() { + this.timeout(15000) + assert.equal(configManager.getConversionRate(), false) + var promise = new Promise( + function (resolve, reject) { + configManager.setCurrentFiat('JPY') + configManager.updateConversionRate().then(function() { + resolve() + }) + }) + + promise.then(function() { + var result = configManager.getConversionRate() + assert.equal(typeof result, 'number') + }).catch(function(err) { + console.log(err) + }) + }) + }) + }) + describe('confirmation', function() { describe('#getConfirmed', function() { @@ -215,4 +291,3 @@ describe('config-manager', function() { }) }) }) - |