Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
Fix account switching with custom node
Browse files Browse the repository at this point in the history
  • Loading branch information
slaweet committed Nov 21, 2017
1 parent 15dcc5f commit bdd3e85
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/store/middlewares/savedAccounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ const savedAccountsMiddleware = store => next => (action) => {
store.dispatch(accountLoggedOut());
store.dispatch(activePeerSet({
publicKey: action.data.publicKey,
network: getNetwork(action.data.network),
network: {
...getNetwork(action.data.network),
address: action.data.address,
},
}));
break;
default:
Expand Down
31 changes: 29 additions & 2 deletions src/store/middlewares/savedAccounts.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { expect } from 'chai';
import { spy, mock } from 'sinon';
import { spy, mock, match } from 'sinon';

import { accountLoggedOut } from '../../actions/account';
import * as peersActions from '../../actions/peers';
import { successToastDisplayed } from '../../actions/toaster';
import actionTypes from '../../constants/actions';
import middleware from './savedAccounts';

describe('SavedAccounts middleware', () => {
let store;
let next;
const address = 'https://testnet.lisk.io';
const publicKey = 'fab9d261ea050b9e326d7e11587eccc343a20e64e29d8781b50fd06683cacc88';

beforeEach(() => {
store = mock();
Expand Down Expand Up @@ -50,11 +53,35 @@ describe('SavedAccounts middleware', () => {
const action = {
type: actionTypes.accountSwitched,
data: {
publicKey: '',
publicKey,
network: 0,
},
};
middleware(store)(next)(action);
expect(store.dispatch).to.have.been.calledWith(accountLoggedOut());
});

it(`should call activePeerSet action on ${actionTypes.accountSwitched} action`, () => {
const code = 2;
const peersActionsMock = mock(peersActions);
peersActionsMock.expects('activePeerSet').withExactArgs(match({
network: {
address,
code,
},
publicKey,
}));

const action = {
type: actionTypes.accountSwitched,
data: {
publicKey,
network: code,
address,
},
};
middleware(store)(next)(action);

peersActionsMock.verify();
});
});

0 comments on commit bdd3e85

Please sign in to comment.