diff options
| author | Erik Larkö <erik@mullvad.net> | 2017-07-03 13:31:49 +0200 |
|---|---|---|
| committer | Erik Larkö <erik@mullvad.net> | 2017-07-04 16:52:03 +0200 |
| commit | 94c6880957759e549c1f0c96c1a7eef8f8fed0a2 (patch) | |
| tree | e2849ff6c12fcdf158d583acb3340c90d257309f | |
| parent | 7c99bf5ab5e56f0ccd8addffb8b68354e8977fea (diff) | |
| download | mullvadvpn-94c6880957759e549c1f0c96c1a7eef8f8fed0a2.tar.xz mullvadvpn-94c6880957759e549c1f0c96c1a7eef8f8fed0a2.zip | |
Connect tests
| -rw-r--r-- | app/lib/backend.js | 11 | ||||
| -rw-r--r-- | test/connect.spec.js | 39 |
2 files changed, 50 insertions, 0 deletions
diff --git a/app/lib/backend.js b/app/lib/backend.js index 2923baf34d..dfd783806c 100644 --- a/app/lib/backend.js +++ b/app/lib/backend.js @@ -5,6 +5,7 @@ import EventEmitter from 'events'; import { servers } from '../config'; import { IpcFacade, RealIpc } from './ipc-facade'; import accountActions from '../redux/account/actions'; +import connectionActions from '../redux/connection/actions'; import type { ReduxStore } from '../redux/store'; import { push } from 'react-router-redux'; @@ -209,6 +210,11 @@ export class Backend { // emit: connecting this._emit('connecting', addr); + this._store.dispatch(connectionActions.connectionChange({ + status: 'connecting', + serverAddress: addr, + })); + this._ipc.setCountry(addr) .then( () => { @@ -216,6 +222,11 @@ export class Backend { }) .then(() => { this._emit('connect', addr); + this._store.dispatch(connectionActions.connectionChange({ + status: 'connected', + serverAddress: addr, + })); + this.sync(); // TODO: This is a pooooooor way of updating the location and the IP and stuff }) .catch(e => { diff --git a/test/connect.spec.js b/test/connect.spec.js new file mode 100644 index 0000000000..0a0f21b1da --- /dev/null +++ b/test/connect.spec.js @@ -0,0 +1,39 @@ +// @flow + +import { expect } from 'chai'; +import connectionActions from '../app/redux/connection/actions'; +import { setupBackendAndStore, checkNextTick } from './helpers/ipc-helpers'; +import { IpcChain } from './helpers/IpcChain'; + +describe('connect', () => { + + it('should invoke set_country and then connect in the backend', (done) => { + const { store, mockIpc, backend } = setupBackendAndStore(); + + const chain = new IpcChain(mockIpc, done); + chain.addRequiredStep('setCountry') + .withInputValidation( + (country) => expect(country).to.equal('example.com') + ) + .done(); + + chain.addRequiredStep('connect') + .done(); + + store.dispatch(connectionActions.connect(backend, 'example.com')); + }); + + it('should update the state with the connection info once connection is established', (done) => { + const { store, backend } = setupBackendAndStore(); + + store.dispatch(connectionActions.connect(backend, 'example.com')); + + checkNextTick( () => { + const state = store.getState().connection; + + expect(state.status).to.equal('connected'); + expect(state.serverAddress).to.equal('example.com'); + }, done); + }); +}); + |
