aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorbitpshr <mail@bitpshr.net>2018-04-16 23:21:06 +0800
committerbitpshr <mail@bitpshr.net>2018-04-16 23:47:06 +0800
commitd0447f90583275868bb72aa7ae8f670bf3668173 (patch)
tree66e9b6bce487e22f030bfc3f892500f744a1ebb8 /test
parenta350e80feea6747a5e10088ac6ec15171a590a65 (diff)
downloadtangerine-wallet-browser-d0447f90583275868bb72aa7ae8f670bf3668173.tar
tangerine-wallet-browser-d0447f90583275868bb72aa7ae8f670bf3668173.tar.gz
tangerine-wallet-browser-d0447f90583275868bb72aa7ae8f670bf3668173.tar.bz2
tangerine-wallet-browser-d0447f90583275868bb72aa7ae8f670bf3668173.tar.lz
tangerine-wallet-browser-d0447f90583275868bb72aa7ae8f670bf3668173.tar.xz
tangerine-wallet-browser-d0447f90583275868bb72aa7ae8f670bf3668173.tar.zst
tangerine-wallet-browser-d0447f90583275868bb72aa7ae8f670bf3668173.zip
Maintain token prices using a background service
Diffstat (limited to 'test')
-rw-r--r--test/unit/token-rates-controller.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/unit/token-rates-controller.js b/test/unit/token-rates-controller.js
new file mode 100644
index 000000000..55bfe7823
--- /dev/null
+++ b/test/unit/token-rates-controller.js
@@ -0,0 +1,28 @@
+const assert = require('assert')
+const sinon = require('sinon')
+const TokenRatesController = require('../../app/scripts/controllers/token-rates')
+const ObservableStore = require('obs-store')
+
+describe('TokenRatesController', () => {
+ it('should listen for preferences store updates', () => {
+ const preferences = new ObservableStore({ tokens: [] })
+ const controller = new TokenRatesController({ preferences })
+ preferences.putState({ tokens: ['foo'] })
+ assert.deepEqual(controller._tokens, ['foo'])
+ })
+
+ it('should poll on correct interval', async () => {
+ const stub = sinon.stub(global, 'setInterval')
+ new TokenRatesController({ interval: 1337 }) // eslint-disable-line no-new
+ assert.strictEqual(stub.getCall(0).args[1], 1337)
+ stub.restore()
+ })
+
+ it('should fetch each token rate based on address', async () => {
+ const controller = new TokenRatesController()
+ controller.fetchExchangeRate = address => address
+ controller.tokens = [{ address: 'foo' }, { address: 'bar' }]
+ await controller.updateExchangeRates()
+ assert.deepEqual(controller.store.getState().contractExchangeRates, { foo: 'foo', bar: 'bar' })
+ })
+})