summaryrefslogtreecommitdiffhomepage
path: root/app/lib
diff options
context:
space:
mode:
authorErik Larkö <erik@mullvad.net>2017-06-30 10:14:36 +0200
committerErik Larkö <erik@mullvad.net>2017-07-03 15:26:08 +0200
commitd06281eb566330a38b13a56bb9fdadbd7ef9aa99 (patch)
treee1bc465e4e1b54b9ccbb8c500ad9b921fd2e16f9 /app/lib
parent005a6094aa48738f54e97d809de6e11f3b966da0 (diff)
downloadmullvadvpn-d06281eb566330a38b13a56bb9fdadbd7ef9aa99.tar.xz
mullvadvpn-d06281eb566330a38b13a56bb9fdadbd7ef9aa99.zip
Add first login workflow test
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/backend.js39
1 files changed, 33 insertions, 6 deletions
diff --git a/app/lib/backend.js b/app/lib/backend.js
index 076a49ca32..4cd2cf49e9 100644
--- a/app/lib/backend.js
+++ b/app/lib/backend.js
@@ -3,6 +3,9 @@ import log from 'electron-log';
import EventEmitter from 'events';
import { servers } from '../config';
import { IpcFacade, RealIpc } from './ipc-facade';
+import accountActions from '../redux/account/actions';
+import type { ReduxStore } from '../redux/store';
+import { push } from 'react-router-redux';
export type EventType = 'connect' | 'connecting' | 'disconnect' | 'login' | 'logging' | 'logout' | 'updatedIp' | 'updatedLocation' | 'updatedReachability';
export type ErrorType = 'NO_CREDIT' | 'NO_INTERNET' | 'INVALID_ACCOUNT';
@@ -61,9 +64,11 @@ export class BackendError extends Error {
export class Backend {
_ipc: IpcFacade;
+ _store: ReduxStore;
_eventEmitter = new EventEmitter();
- constructor(ipc: ?IpcFacade) {
+ constructor(store: ReduxStore, ipc: ?IpcFacade) {
+ this._store = store;
this._ipc = ipc || new RealIpc('');
this._registerIpcListeners();
this._startReachability();
@@ -131,17 +136,24 @@ export class Backend {
};
}
- login(account: string) {
- log.info('Attempting to login with account number', account);
+
+ login(accountNumber: string) {
+ log.info('Attempting to login with account number', accountNumber);
// emit: logging in
- this._emit('logging', { accountNumber: account }, null);
+ this._emit('logging', { accountNumber: accountNumber }, null);
+
+ this._store.dispatch(accountActions.loginChange({
+ accountNumber: accountNumber,
+ status: 'connecting',
+ error: null,
+ }));
- this._ipc.getAccountData(account)
+ this._ipc.getAccountData(accountNumber)
.then( response => {
log.info('Account exists', response);
- return this._ipc.setAccount(account)
+ return this._ipc.setAccount(accountNumber)
.then( () => response );
}).then( accountData => {
@@ -151,13 +163,28 @@ export class Backend {
paidUntil: accountData.paid_until,
}, undefined);
+ this._store.dispatch(accountActions.loginChange({
+ status: 'ok',
+ paidUntil: accountData.paid_until,
+ error: null,
+ }));
+
+ this._store.dispatch(push('/connect'));
}).catch(e => {
log.error('Failed to log in', e);
+
+ // TODO: This is not true. If there is a communication link failure the promise will be rejected too
const err = new BackendError('INVALID_ACCOUNT');
+ this._store.dispatch(accountActions.loginChange({
+ status: 'failed',
+ error: err,
+ }));
+
this._emit('login', {}, err);
});
}
+
logout() {
// @TODO: What does it mean for a logout to be successful or failed?
this._ipc.setAccount('')