diff options
author | Dan Finlay <dan@danfinlay.com> | 2016-04-19 02:41:29 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2016-04-19 02:41:29 +0800 |
commit | 65d73d7bb4b091021988b6115d518cf3914952ed (patch) | |
tree | 643559fde2298a1c1a71488c53339c6f372e85e2 /test/unit/actions/restore_vault_test.js | |
parent | 8b62a8bec288120eee71523886f4c2df83b136ff (diff) | |
download | tangerine-wallet-browser-65d73d7bb4b091021988b6115d518cf3914952ed.tar.gz tangerine-wallet-browser-65d73d7bb4b091021988b6115d518cf3914952ed.tar.zst tangerine-wallet-browser-65d73d7bb4b091021988b6115d518cf3914952ed.zip |
Unify test suites
Diffstat (limited to 'test/unit/actions/restore_vault_test.js')
-rw-r--r-- | test/unit/actions/restore_vault_test.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/test/unit/actions/restore_vault_test.js b/test/unit/actions/restore_vault_test.js new file mode 100644 index 000000000..5873a0181 --- /dev/null +++ b/test/unit/actions/restore_vault_test.js @@ -0,0 +1,54 @@ +var jsdom = require('mocha-jsdom') +var assert = require('assert') +var freeze = require('deep-freeze-strict') +var path = require('path') +var sinon = require('sinon') + +var actions = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'actions.js')) +var reducers = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'reducers.js')) + +describe('#recoverFromSeed(password, seed)', function() { + + beforeEach(function() { + // sinon allows stubbing methods that are easily verified + this.sinon = sinon.sandbox.create() + }) + + afterEach(function() { + // sinon requires cleanup otherwise it will overwrite context + this.sinon.restore() + }) + + // stub out account manager + actions._setAccountManager({ + recoverFromSeed(pw, seed, cb) { cb() }, + }) + + it('sets metamask.isUnlocked to true', function() { + var initialState = { + metamask: { + isUnlocked: false, + isInitialized: false, + } + } + freeze(initialState) + + const restorePhrase = 'invite heavy among daring outdoor dice jelly coil stable note seat vicious' + const password = 'foo' + const dispatchFunc = actions.recoverFromSeed(password, restorePhrase) + + var dispatchStub = this.sinon.stub() + dispatchStub.withArgs({ TYPE: actions.unlockMetamask() }).onCall(0) + dispatchStub.withArgs({ TYPE: actions.showAccountsPage() }).onCall(1) + + var action + var resultingState = initialState + dispatchFunc((newAction) => { + action = newAction + resultingState = reducers(resultingState, action) + }) + + assert.equal(resultingState.metamask.isUnlocked, true, 'was unlocked') + assert.equal(resultingState.metamask.isInitialized, true, 'was initialized') + }); +}); |