Get passing existing saga tests
This commit is contained in:
parent
b1b17a155f
commit
edcad4b7a9
|
@ -4,7 +4,7 @@ import { Web3Wallet } from 'libs/wallet';
|
|||
import { SagaIterator } from 'redux-saga';
|
||||
import { select, put, takeEvery, call } from 'redux-saga/effects';
|
||||
import { changeNodeIntent, TypeKeys, web3SetNode } from 'actions/config';
|
||||
import { getNodeId, getStaticAltNodeToWeb3 } from 'selectors/config';
|
||||
import { getNodeId, getStaticAltNodeIdToWeb3 } from 'selectors/config';
|
||||
import { setupWeb3Node, Web3Service } from 'libs/nodes/web3';
|
||||
import { Web3NodeConfig } from 'types/node';
|
||||
|
||||
|
@ -32,7 +32,7 @@ export function* unsetWeb3NodeOnWalletEvent(action): SagaIterator {
|
|||
return;
|
||||
}
|
||||
|
||||
const altNode = yield select(getStaticAltNodeToWeb3);
|
||||
const altNode = yield select(getStaticAltNodeIdToWeb3);
|
||||
// switch back to a node with the same network as MetaMask/Mist
|
||||
yield put(changeNodeIntent(altNode));
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ export function* unsetWeb3Node(): SagaIterator {
|
|||
return;
|
||||
}
|
||||
|
||||
const altNode = yield select(getStaticAltNodeToWeb3);
|
||||
const altNode = yield select(getStaticAltNodeIdToWeb3);
|
||||
// switch back to a node with the same network as MetaMask/Mist
|
||||
yield put(changeNodeIntent(altNode));
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ export const getCustomNodeFromId = (
|
|||
nodeId: string
|
||||
): CustomNodeConfig | undefined => getCustomNodeConfigs(state)[nodeId];
|
||||
|
||||
export const getStaticAltNodeToWeb3 = (state: AppState) => {
|
||||
export const getStaticAltNodeIdToWeb3 = (state: AppState) => {
|
||||
const { web3, ...configs } = getStaticNodeConfigs(state);
|
||||
if (!web3) {
|
||||
return SELECTED_NODE_INITIAL_STATE.nodeId;
|
||||
|
|
|
@ -7,32 +7,28 @@ import {
|
|||
handleNodeChangeIntent,
|
||||
handlePollOfflineStatus,
|
||||
pollOfflineStatus,
|
||||
reload,
|
||||
switchToNewNode
|
||||
reload
|
||||
} from 'sagas/config/node';
|
||||
import {
|
||||
getNodeId,
|
||||
getNodeConfig,
|
||||
getOffline,
|
||||
getCustomNodeConfigs,
|
||||
getCustomNetworkConfigs,
|
||||
isStaticNodeId,
|
||||
getStaticNodeFromId,
|
||||
getNetworkConfigById,
|
||||
getCustomNodeFromId
|
||||
getCustomNodeFromId,
|
||||
getStaticAltNodeIdToWeb3
|
||||
} from 'selectors/config';
|
||||
import { Web3Wallet } from 'libs/wallet';
|
||||
import { RPCNode } from 'libs/nodes';
|
||||
import { showNotification } from 'actions/notifications';
|
||||
import { translateRaw } from 'translations';
|
||||
import { StaticNodeConfig } from 'types/node';
|
||||
import { staticNodesExpectedState } from './nodes/staticNodes.spec';
|
||||
import { metaExpectedState } from './meta/meta.spec';
|
||||
import { selectedNodeExpectedState } from './nodes/selectedNode.spec';
|
||||
import { staticNetworksExpectedState } from './networks/staticNetworks.spec';
|
||||
import { customNetworksExpectedState } from './networks/customNetworks.spec';
|
||||
import { StaticNetworkConfig } from '../../../shared/types/network';
|
||||
import { customNodesExpectedState, firstCustomNodeId } from './nodes/customNodes.spec';
|
||||
import { unsetWeb3Node, unsetWeb3NodeOnWalletEvent } from 'sagas/config/web3';
|
||||
|
||||
// init module
|
||||
configuredStore.getState();
|
||||
|
||||
|
@ -268,20 +264,19 @@ describe('handleNodeChangeIntent*', () => {
|
|||
|
||||
describe('unsetWeb3Node*', () => {
|
||||
const node = 'web3';
|
||||
const mockNodeConfig = { network: 'ETH' } as any;
|
||||
const newNode = equivalentNodeOrDefault(mockNodeConfig);
|
||||
const alternativeNodeId = 'eth_mew';
|
||||
const gen = unsetWeb3Node();
|
||||
|
||||
it('should select getNode', () => {
|
||||
expect(gen.next().value).toEqual(select(getNodeId));
|
||||
});
|
||||
|
||||
it('should select getNodeConfig', () => {
|
||||
expect(gen.next(node).value).toEqual(select(getNodeConfig));
|
||||
it('should select an alternative node to web3', () => {
|
||||
expect(gen.next(node).value).toEqual(select(getStaticAltNodeIdToWeb3));
|
||||
});
|
||||
|
||||
it('should put changeNodeIntent', () => {
|
||||
expect(gen.next(mockNodeConfig).value).toEqual(put(changeNodeIntent(newNode)));
|
||||
expect(gen.next(alternativeNodeId).value).toEqual(put(changeNodeIntent(alternativeNodeId)));
|
||||
});
|
||||
|
||||
it('should be done', () => {
|
||||
|
@ -298,22 +293,20 @@ describe('unsetWeb3Node*', () => {
|
|||
|
||||
describe('unsetWeb3NodeOnWalletEvent*', () => {
|
||||
const fakeAction = {};
|
||||
const mockNode = 'web3';
|
||||
const mockNodeConfig: Partial<StaticNodeConfig> = { network: 'ETH' };
|
||||
const mockNodeId = 'web3';
|
||||
const alternativeNodeId = 'eth_mew';
|
||||
const gen = unsetWeb3NodeOnWalletEvent(fakeAction);
|
||||
|
||||
it('should select getNode', () => {
|
||||
expect(gen.next().value).toEqual(select(getNodeId));
|
||||
});
|
||||
|
||||
it('should select getNodeConfig', () => {
|
||||
expect(gen.next(mockNode).value).toEqual(select(getNodeConfig));
|
||||
it('should select an alternative node to web3', () => {
|
||||
expect(gen.next(mockNodeId).value).toEqual(select(getStaticAltNodeIdToWeb3));
|
||||
});
|
||||
|
||||
it('should put changeNodeIntent', () => {
|
||||
expect(gen.next(mockNodeConfig).value).toEqual(
|
||||
put(changeNodeIntent(equivalentNodeOrDefault(mockNodeConfig as any)))
|
||||
);
|
||||
expect(gen.next(alternativeNodeId).value).toEqual(put(changeNodeIntent(alternativeNodeId)));
|
||||
});
|
||||
|
||||
it('should be done', () => {
|
||||
|
@ -337,51 +330,3 @@ describe('unsetWeb3NodeOnWalletEvent*', () => {
|
|||
expect(gen2.next().done).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('equivalentNodeOrDefault', () => {
|
||||
const originalNodeList = Object.keys(NODES);
|
||||
const appDefaultNode = configInitialState.nodeSelection;
|
||||
const mockNodeConfig = {
|
||||
network: 'ETH',
|
||||
service: 'fakeService',
|
||||
lib: new RPCNode('fakeEndpoint'),
|
||||
estimateGas: false
|
||||
};
|
||||
|
||||
afterEach(() => {
|
||||
Object.keys(NODES).forEach(node => {
|
||||
if (originalNodeList.indexOf(node) === -1) {
|
||||
delete NODES[node];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should return node with equivalent network', () => {
|
||||
const node = equivalentNodeOrDefault({
|
||||
...mockNodeConfig,
|
||||
network: 'Kovan'
|
||||
});
|
||||
expect(NODES[node].network).toEqual('Kovan');
|
||||
});
|
||||
|
||||
it('should return app default if no eqivalent is found', () => {
|
||||
const node = equivalentNodeOrDefault({
|
||||
...mockNodeConfig,
|
||||
network: 'noEqivalentExists'
|
||||
} as any);
|
||||
expect(node).toEqual(appDefaultNode);
|
||||
});
|
||||
|
||||
it('should ignore web3 from node list', () => {
|
||||
NODES.web3 = {
|
||||
...mockNodeConfig,
|
||||
network: 'uniqueToWeb3'
|
||||
} as any;
|
||||
|
||||
const node = equivalentNodeOrDefault({
|
||||
...mockNodeConfig,
|
||||
network: 'uniqueToWeb3'
|
||||
} as any);
|
||||
expect(node).toEqual(appDefaultNode);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue