aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/app/controllers/currency-controller-test.js
diff options
context:
space:
mode:
authorkumavis <kumavis@users.noreply.github.com>2018-05-23 04:02:41 +0800
committerGitHub <noreply@github.com>2018-05-23 04:02:41 +0800
commitcee55b47d03006630b1dbe038c6008654ca8f674 (patch)
treefe818a80ee98ee76a53e9be6087c09be02241503 /test/unit/app/controllers/currency-controller-test.js
parent492b4a674392e4772ef8e2cc8f5836b882cfeec7 (diff)
parent238f2eb179895bbb9e2a2ec26863041564c90a9d (diff)
downloadtangerine-wallet-browser-cee55b47d03006630b1dbe038c6008654ca8f674.tar
tangerine-wallet-browser-cee55b47d03006630b1dbe038c6008654ca8f674.tar.gz
tangerine-wallet-browser-cee55b47d03006630b1dbe038c6008654ca8f674.tar.bz2
tangerine-wallet-browser-cee55b47d03006630b1dbe038c6008654ca8f674.tar.lz
tangerine-wallet-browser-cee55b47d03006630b1dbe038c6008654ca8f674.tar.xz
tangerine-wallet-browser-cee55b47d03006630b1dbe038c6008654ca8f674.tar.zst
tangerine-wallet-browser-cee55b47d03006630b1dbe038c6008654ca8f674.zip
Merge pull request #4321 from MetaMask/testing
MM controller tests and reorganizing test files
Diffstat (limited to 'test/unit/app/controllers/currency-controller-test.js')
-rw-r--r--test/unit/app/controllers/currency-controller-test.js81
1 files changed, 81 insertions, 0 deletions
diff --git a/test/unit/app/controllers/currency-controller-test.js b/test/unit/app/controllers/currency-controller-test.js
new file mode 100644
index 000000000..1941d1c43
--- /dev/null
+++ b/test/unit/app/controllers/currency-controller-test.js
@@ -0,0 +1,81 @@
+// polyfill fetch
+global.fetch = global.fetch || require('isomorphic-fetch')
+
+const assert = require('assert')
+const nock = require('nock')
+const CurrencyController = require('../../../../app/scripts/controllers/currency')
+
+describe('currency-controller', 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)
+ nock('https://api.infura.io')
+ .get('/v1/ticker/ethusd')
+ .reply(200, '{"base": "ETH", "quote": "USD", "bid": 288.45, "ask": 288.46, "volume": 112888.17569277, "exchange": "bitfinex", "total_volume": 272175.00106721005, "num_exchanges": 8, "timestamp": 1506444677}')
+
+ assert.equal(currencyController.getConversionRate(), 0)
+ currencyController.setCurrentCurrency('usd')
+ currencyController.updateConversionRate()
+ .then(function () {
+ var result = currencyController.getConversionRate()
+ 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)
+
+ nock('https://api.infura.io')
+ .get('/v1/ticker/ethjpy')
+ .reply(200, '{"base": "ETH", "quote": "JPY", "bid": 32300.0, "ask": 32400.0, "volume": 247.4616071, "exchange": "kraken", "total_volume": 247.4616071, "num_exchanges": 1, "timestamp": 1506444676}')
+
+
+ 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 (done, err) {
+ done(err)
+ })
+ })
+ })
+ })
+})