diff options
| author | Andrej Mihajlov <and@codeispoetry.ru> | 2017-02-28 16:35:03 +0000 |
|---|---|---|
| committer | Andrej Mihajlov <and@codeispoetry.ru> | 2017-02-28 16:35:03 +0000 |
| commit | 04b50f53e5d2e5941e934e6a76764f835e8afdd3 (patch) | |
| tree | 95794c9716b13df379b481e39140b16721c761b8 | |
| parent | 9fccac2bdc7b05f70b0e884fa9cfa90d95bda373 (diff) | |
| download | mullvadvpn-04b50f53e5d2e5941e934e6a76764f835e8afdd3.tar.xz mullvadvpn-04b50f53e5d2e5941e934e6a76764f835e8afdd3.zip | |
Add connection test
| -rw-r--r-- | test/actions.spec.js | 45 |
1 files changed, 37 insertions, 8 deletions
diff --git a/test/actions.spec.js b/test/actions.spec.js index 1ab7049ed4..18e4796a01 100644 --- a/test/actions.spec.js +++ b/test/actions.spec.js @@ -3,6 +3,7 @@ import configureMockStore from 'redux-mock-store'; import thunk from 'redux-thunk'; import Backend from '../app/lib/backend'; import userActions from '../app/actions/user'; +import connectActions from '../app/actions/connect'; import mapBackendEventsToReduxActions from '../app/lib/backend-redux-actions'; import { LoginState, ConnectionState, defaultServer } from '../app/constants'; @@ -27,6 +28,12 @@ const mockState = () => { }; }; +const mockBackend = (store) => { + const backend = new Backend(); + mapBackendEventsToReduxActions(backend, store); + return backend; +} + const filterIpUpdateActions = (actions) => { return actions.filter((action) => { return !(action.type === 'CONNECTION_CHANGE' && action.payload.clientIp); @@ -34,18 +41,16 @@ const filterIpUpdateActions = (actions) => { }; describe('actions', function() { - this.timeout(5000); + this.timeout(10000); it('should login', (done) => { const expectedActions = [ { type: 'USER_LOGIN_CHANGE', payload: { status: 'connecting', error: null, account: '111123456789' } }, - { type: 'USER_LOGIN_CHANGE', payload: { status: 'ok', error: undefined } } + { type: 'USER_LOGIN_CHANGE', payload: { status: 'ok', error: null } } ]; - const backend = new Backend(); const store = mockStore(mockState()); - - mapBackendEventsToReduxActions(backend, store); + const backend = mockBackend(store); backend.once(Backend.EventType.login, () => { const storeActions = filterIpUpdateActions(store.getActions()); @@ -69,10 +74,8 @@ describe('actions', function() { } }); - const backend = new Backend(); const store = mockStore(state); - - mapBackendEventsToReduxActions(backend, store); + const backend = mockBackend(store); backend.once(Backend.EventType.logout, () => { const storeActions = filterIpUpdateActions(store.getActions()); @@ -84,4 +87,30 @@ describe('actions', function() { store.dispatch(userActions.logout(backend)); }); + it('should connect to VPN server', (done) => { + const expectedActions = [ + { type: 'CONNECTION_CHANGE', payload: { serverAddress: '1.2.3.4', status: 'connecting', error: null } }, + { type: 'CONNECTION_CHANGE', payload: { status: 'connected', error: null } } + ]; + + let state = Object.assign(mockState(), { + user: { + account: '1111234567890', + status: LoginState.ok + } + }); + + const store = mockStore(state); + const backend = mockBackend(store); + + backend.once(Backend.EventType.connect, () => { + const storeActions = filterIpUpdateActions(store.getActions()); + + expect(storeActions).deep.equal(expectedActions); + done(); + }); + + store.dispatch(connectActions.connect(backend, '1.2.3.4')); + }); + }); |
