aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2017-02-03 15:32:24 +0800
committerkumavis <aaron@kumavis.me>2017-02-03 15:32:24 +0800
commit9e4ef45b6ac460e6539e0f79ad5c78959fa1c4cb (patch)
tree985284da2a2d002b2f591319d12bf980c3e4edee /test
parentb233e7e37c56852080bdc7b1843eb68ba96b5382 (diff)
downloadtangerine-wallet-browser-9e4ef45b6ac460e6539e0f79ad5c78959fa1c4cb.tar
tangerine-wallet-browser-9e4ef45b6ac460e6539e0f79ad5c78959fa1c4cb.tar.gz
tangerine-wallet-browser-9e4ef45b6ac460e6539e0f79ad5c78959fa1c4cb.tar.bz2
tangerine-wallet-browser-9e4ef45b6ac460e6539e0f79ad5c78959fa1c4cb.tar.lz
tangerine-wallet-browser-9e4ef45b6ac460e6539e0f79ad5c78959fa1c4cb.tar.xz
tangerine-wallet-browser-9e4ef45b6ac460e6539e0f79ad5c78959fa1c4cb.tar.zst
tangerine-wallet-browser-9e4ef45b6ac460e6539e0f79ad5c78959fa1c4cb.zip
migration #9 - break out CurrencyController substate
Diffstat (limited to 'test')
-rw-r--r--test/unit/config-manager-test.js75
-rw-r--r--test/unit/currency-controller-test.js87
2 files changed, 87 insertions, 75 deletions
diff --git a/test/unit/config-manager-test.js b/test/unit/config-manager-test.js
index acc73ebb4..c6f60192f 100644
--- a/test/unit/config-manager-test.js
+++ b/test/unit/config-manager-test.js
@@ -14,81 +14,6 @@ describe('config-manager', function() {
configManager = configManagerGen()
})
- describe('currency conversions', function() {
-
- describe('#setCurrentFiat', function() {
- it('should return USD as default', function() {
- assert.equal(configManager.getCurrentFiat(), 'USD')
- })
-
- it('should be able to set to other currency', function() {
- assert.equal(configManager.getCurrentFiat(), 'USD')
- configManager.setCurrentFiat('JPY')
- var result = configManager.getCurrentFiat()
- assert.equal(result, 'JPY')
- })
- })
-
- describe('#getConversionRate', function() {
- it('should return undefined 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)
- 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(), 0)
- 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(), 0)
-
- var jpyMock = 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().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('#getConfirmedDisclaimer', function() {
diff --git a/test/unit/currency-controller-test.js b/test/unit/currency-controller-test.js
new file mode 100644
index 000000000..c57b522c7
--- /dev/null
+++ b/test/unit/currency-controller-test.js
@@ -0,0 +1,87 @@
+// polyfill fetch
+global.fetch = global.fetch || require('isomorphic-fetch')
+
+const assert = require('assert')
+const extend = require('xtend')
+const rp = require('request-promise')
+const nock = require('nock')
+const CurrencyController = require('../../app/scripts/lib/controllers/currency')
+
+describe('config-manager', function() {
+ var currencyController
+
+ beforeEach(function() {
+ currencyController = new CurrencyController()
+ })
+
+ describe('currency conversions', function() {
+
+ describe('#setCurrentCurrency', function() {
+ it('should return USD as default', function() {
+ assert.equal(currencyController.getCurrentCurrency(), 'USD')
+ })
+
+ it('should be able to set to other currency', function() {
+ assert.equal(currencyController.getCurrentCurrency(), 'USD')
+ currencyController.setCurrentCurrency('JPY')
+ var result = currencyController.getCurrentCurrency()
+ assert.equal(result, 'JPY')
+ })
+ })
+
+ describe('#getConversionRate', function() {
+ it('should return undefined if non-existent', function() {
+ var result = currencyController.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)
+ 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(currencyController.getConversionRate(), 0)
+ currencyController.setCurrentCurrency('USD')
+ currencyController.updateConversionRate()
+ .then(function() {
+ var result = currencyController.getConversionRate()
+ console.log('currencyController.getConversionRate:', result)
+ assert.equal(typeof result, 'number')
+ done()
+ }).catch(function(err) {
+ done(err)
+ })
+
+ })
+
+ it('should work for JPY as well.', function() {
+ this.timeout(15000)
+ assert.equal(currencyController.getConversionRate(), 0)
+
+ var jpyMock = 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) {
+ currencyController.setCurrentCurrency('JPY')
+ currencyController.updateConversionRate().then(function() {
+ resolve()
+ })
+ })
+
+ promise.then(function() {
+ var result = currencyController.getConversionRate()
+ assert.equal(typeof result, 'number')
+ }).catch(function(err) {
+ done(err)
+ })
+ })
+ })
+ })
+
+})