summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorErik Larkö <erik@mullvad.net>2017-07-25 13:28:05 +0200
committerErik Larkö <erik@mullvad.net>2017-08-08 09:50:58 +0200
commit3ec32f23e93c8a487da82db86516ad12782b54f6 (patch)
tree1ca272253ff2b242bca265c13dd4b3c260bc62a7
parentd375be8e56975d57f1ca67f28459609de6c10fa5 (diff)
downloadmullvadvpn-3ec32f23e93c8a487da82db86516ad12782b54f6.tar.xz
mullvadvpn-3ec32f23e93c8a487da82db86516ad12782b54f6.zip
Added NEW_LOCATION action
-rw-r--r--app/lib/backend.js2
-rw-r--r--app/redux/connection/actions.js24
-rw-r--r--app/redux/connection/reducers.js2
-rw-r--r--test/connection-info.spec.js31
4 files changed, 54 insertions, 5 deletions
diff --git a/app/lib/backend.js b/app/lib/backend.js
index bc6eeeb8ff..e5cf3765c4 100644
--- a/app/lib/backend.js
+++ b/app/lib/backend.js
@@ -112,7 +112,7 @@ export class Backend {
country: location.country,
city: location.city
};
- this._store.dispatch(connectionActions.connectionChange(newLocation));
+ this._store.dispatch(connectionActions.newLocation(newLocation));
})
.catch(e => {
log.info('Failed getting new location', e);
diff --git a/app/redux/connection/actions.js b/app/redux/connection/actions.js
index 142feb9d79..0a7591fa11 100644
--- a/app/redux/connection/actions.js
+++ b/app/redux/connection/actions.js
@@ -5,6 +5,7 @@ import { clipboard } from 'electron';
import type { Backend } from '../../lib/backend';
import type { ConnectionReduxState } from './reducers.js';
import type { ReduxGetState, ReduxDispatch } from '../store';
+import type { Coordinate2d } from '../../types';
const connect = (backend: Backend, addr: string) => () => backend.connect(addr);
@@ -24,11 +25,24 @@ type ConnectionChangeAction = {
type: 'CONNECTION_CHANGE',
newData: $Shape<ConnectionReduxState>,
};
+
type NewPublicIpAction = {
type: 'NEW_PUBLIC_IP',
ip: string,
};
-export type ConnectionAction = ConnectionChangeAction | NewPublicIpAction;
+
+type Location = {
+ location: Coordinate2d,
+ country: string,
+ city: string,
+};
+
+type NewLocationAction = {
+ type: 'NEW_LOCATION',
+ newLocation: Location,
+};
+
+export type ConnectionAction = ConnectionChangeAction | NewPublicIpAction | NewLocationAction;
function connectionChange(newData: $Shape<ConnectionReduxState>): ConnectionChangeAction {
return {
@@ -44,6 +58,12 @@ function newPublicIp(ip: string): NewPublicIpAction {
};
}
+function newLocation(newLoc: Location): NewLocationAction {
+ return {
+ type: 'NEW_LOCATION',
+ newLocation: newLoc,
+ };
+}
-export default { connect, disconnect, copyIPAddress, connectionChange, newPublicIp };
+export default { connect, disconnect, copyIPAddress, connectionChange, newPublicIp, newLocation };
diff --git a/app/redux/connection/reducers.js b/app/redux/connection/reducers.js
index 2426f7eddd..7bf9abebc9 100644
--- a/app/redux/connection/reducers.js
+++ b/app/redux/connection/reducers.js
@@ -32,6 +32,8 @@ export default function(state: ConnectionReduxState = initialState, action: Redu
return { ...state, ...action.newData };
case 'NEW_PUBLIC_IP':
return { ...state, ...{ clientIp: action.ip }};
+ case 'NEW_LOCATION':
+ return { ...state, ...action.newLocation };
default:
return state;
}
diff --git a/test/connection-info.spec.js b/test/connection-info.spec.js
index 16600d4389..76a97a35f7 100644
--- a/test/connection-info.spec.js
+++ b/test/connection-info.spec.js
@@ -8,12 +8,39 @@ 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);
+ const store = createStore();
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');
});
+
+ it('should contain the latest location', () => {
+ const store = createStore();
+
+ const firstLoc = {
+ location: [1, 2],
+ city: 'a',
+ country: 'b',
+ };
+ const secondLoc = {
+ location: [3, 4],
+ city: 'c',
+ country: 'd',
+ };
+
+ store.dispatch(connectionActions.newLocation(firstLoc));
+ store.dispatch(connectionActions.newLocation(secondLoc));
+
+ const { location, city, country } = store.getState().connection;
+ expect(location).to.equal(secondLoc.location);
+ expect(city).to.equal(secondLoc.city);
+ expect(country).to.equal(secondLoc.country);
+ });
});
+
+function createStore() {
+ const memoryHistory = createMemoryHistory();
+ return configureStore(null, memoryHistory);
+}