2021-05-07 21:38:24 +02:00
|
|
|
import { strict as assert } from 'assert';
|
2021-02-04 19:15:23 +01:00
|
|
|
import sinon from 'sinon';
|
|
|
|
import { ObservableStore } from '@metamask/obs-store';
|
2021-03-16 22:00:08 +01:00
|
|
|
import TokenRatesController from './token-rates';
|
2018-04-16 17:21:06 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('TokenRatesController', function () {
|
2021-02-12 18:41:53 +01:00
|
|
|
let nativeCurrency;
|
|
|
|
let getNativeCurrency;
|
|
|
|
beforeEach(function () {
|
|
|
|
nativeCurrency = 'ETH';
|
|
|
|
getNativeCurrency = () => nativeCurrency;
|
|
|
|
});
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should listen for preferences store updates', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const preferences = new ObservableStore({ tokens: [] });
|
|
|
|
preferences.putState({ tokens: ['foo'] });
|
2021-02-12 18:41:53 +01:00
|
|
|
const controller = new TokenRatesController({
|
|
|
|
preferences,
|
|
|
|
getNativeCurrency,
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.deepEqual(controller._tokens, ['foo']);
|
|
|
|
});
|
2018-04-16 17:21:06 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should poll on correct interval', async function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const stub = sinon.stub(global, 'setInterval');
|
|
|
|
const preferences = new ObservableStore({ tokens: [] });
|
|
|
|
preferences.putState({ tokens: ['foo'] });
|
2021-02-12 18:41:53 +01:00
|
|
|
const controller = new TokenRatesController({
|
|
|
|
preferences,
|
|
|
|
getNativeCurrency,
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
controller.start(1337);
|
2020-06-05 20:36:55 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(stub.getCall(0).args[1], 1337);
|
|
|
|
stub.restore();
|
|
|
|
controller.stop();
|
|
|
|
});
|
|
|
|
});
|