diff options
| author | Erik Larkö <erik@mullvad.net> | 2017-07-28 07:33:29 +0200 |
|---|---|---|
| committer | Erik Larkö <erik@mullvad.net> | 2017-07-28 07:33:29 +0200 |
| commit | a196629083e1fb634a1d65e816a1b4bdfbdeb072 (patch) | |
| tree | 7f2f9b8ae3f2c2927345b31c86465464b538e923 | |
| parent | fd803f74404a1a10f290cbd0852c4ee9a1b2d7ae (diff) | |
| parent | 8df67c161683773092668130deec3f50c23b9205 (diff) | |
| download | mullvadvpn-a196629083e1fb634a1d65e816a1b4bdfbdeb072.tar.xz mullvadvpn-a196629083e1fb634a1d65e816a1b4bdfbdeb072.zip | |
Merge branch 'new-ip-action'
| -rw-r--r-- | app/lib/backend.js | 2 | ||||
| -rw-r--r-- | app/redux/connection/actions.js | 18 | ||||
| -rw-r--r-- | app/redux/connection/reducers.js | 9 | ||||
| -rw-r--r-- | app/redux/store.js | 5 | ||||
| -rw-r--r-- | test/connection-info.spec.js | 19 |
5 files changed, 45 insertions, 8 deletions
diff --git a/app/lib/backend.js b/app/lib/backend.js index c8bea1600b..3c322afa6d 100644 --- a/app/lib/backend.js +++ b/app/lib/backend.js @@ -98,7 +98,7 @@ export class Backend { this._ipc.getIp() .then( ip => { log.info('Got ip', ip); - this._store.dispatch(connectionActions.connectionChange({ clientIp: ip })); + this._store.dispatch(connectionActions.newPublicIp(ip)); }) .catch(e => { log.info('Failed syncing with the backend', e); diff --git a/app/redux/connection/actions.js b/app/redux/connection/actions.js index 9f573bede2..142feb9d79 100644 --- a/app/redux/connection/actions.js +++ b/app/redux/connection/actions.js @@ -19,10 +19,16 @@ const copyIPAddress = () => { }; -export type ConnectionChangeAction = { + +type ConnectionChangeAction = { type: 'CONNECTION_CHANGE', newData: $Shape<ConnectionReduxState>, }; +type NewPublicIpAction = { + type: 'NEW_PUBLIC_IP', + ip: string, +}; +export type ConnectionAction = ConnectionChangeAction | NewPublicIpAction; function connectionChange(newData: $Shape<ConnectionReduxState>): ConnectionChangeAction { return { @@ -31,5 +37,13 @@ function connectionChange(newData: $Shape<ConnectionReduxState>): ConnectionChan }; } +function newPublicIp(ip: string): NewPublicIpAction { + return { + type: 'NEW_PUBLIC_IP', + ip: ip, + }; +} + + -export default { connect, disconnect, copyIPAddress, connectionChange }; +export default { connect, disconnect, copyIPAddress, connectionChange, newPublicIp }; diff --git a/app/redux/connection/reducers.js b/app/redux/connection/reducers.js index 07bdf20b16..2426f7eddd 100644 --- a/app/redux/connection/reducers.js +++ b/app/redux/connection/reducers.js @@ -27,9 +27,12 @@ const initialState: ConnectionReduxState = { export default function(state: ConnectionReduxState = initialState, action: ReduxAction): ConnectionReduxState { - if (action.type === 'CONNECTION_CHANGE') { + switch (action.type) { + case 'CONNECTION_CHANGE': return { ...state, ...action.newData }; + case 'NEW_PUBLIC_IP': + return { ...state, ...{ clientIp: action.ip }}; + default: + return state; } - - return state; } diff --git a/app/redux/store.js b/app/redux/store.js index 93b748ed7a..0a72a1869a 100644 --- a/app/redux/store.js +++ b/app/redux/store.js @@ -16,7 +16,7 @@ import type { AccountReduxState } from './account/reducers.js'; import type { ConnectionReduxState } from './connection/reducers.js'; import type { SettingsReduxState } from './settings/reducers.js'; -import type { ConnectionChangeAction } from './connection/actions.js'; +import type { ConnectionAction } from './connection/actions.js'; import type { LoginChangeAction } from './account/actions.js'; import type { UpdateSettingsAction } from './settings/actions.js'; @@ -28,7 +28,8 @@ export type ReduxState = { export type ReduxAction = LoginChangeAction | UpdateSettingsAction - | ConnectionChangeAction; + | ConnectionAction; + export type ReduxStore = Store<ReduxState, ReduxAction, ReduxDispatch>; export type ReduxGetState = () => ReduxState; export type ReduxDispatch = (action: ReduxAction | ReduxThunk) => any; diff --git a/test/connection-info.spec.js b/test/connection-info.spec.js new file mode 100644 index 0000000000..16600d4389 --- /dev/null +++ b/test/connection-info.spec.js @@ -0,0 +1,19 @@ +// @flow + +import { expect } from 'chai'; +import { createMemoryHistory } from 'history'; +import configureStore from '../app/redux/store'; +import connectionActions from '../app/redux/connection/actions'; + +describe('The connection state', () => { + + it('should contain the latest IP', () => { + const memoryHistory = createMemoryHistory(); + const store = configureStore(null, memoryHistory); + + store.dispatch(connectionActions.newPublicIp('1.2.3.4')); + store.dispatch(connectionActions.newPublicIp('5.6.7.8')); + + expect(store.getState().connection.clientIp).to.equal('5.6.7.8'); + }); +}); |
