diff options
| -rw-r--r-- | app/app.js | 4 | ||||
| -rw-r--r-- | app/lib/backend.js | 15 | ||||
| -rw-r--r-- | test/auth.spec.js | 4 | ||||
| -rw-r--r-- | test/helpers/ipc-helpers.js | 9 | ||||
| -rw-r--r-- | test/mocks/redux.js | 19 |
5 files changed, 22 insertions, 29 deletions
diff --git a/app/app.js b/app/app.js index 6536de4983..5cdf7e78d9 100644 --- a/app/app.js +++ b/app/app.js @@ -30,6 +30,10 @@ ipcRenderer.on('backend-info', (_event, args) => { .then( () => { return backend.syncRelayConstraints(); }) + .then( () => { + const { settings } = store.getState(); + return backend.connect(settings.relayConstraints.host); + }) .catch( e => { if (e.type === 'NO_ACCOUNT') { log.debug('No user set in the backend, showing window'); diff --git a/app/lib/backend.js b/app/lib/backend.js index 496ad9b3b6..fe828ba6c8 100644 --- a/app/lib/backend.js +++ b/app/lib/backend.js @@ -186,12 +186,18 @@ export class Backend { log.info('Log in complete'); this._store.dispatch(accountActions.loginSuccessful(accountData.expiry)); + return this.syncRelayConstraints(); + }) + .then( () => { // Redirect the user after some time to allow for // the 'Login Successful' screen to be visible setTimeout(() => { + const { host } = this._store.getState().settings.relayConstraints; + log.debug('Autoconnecting to', host); + this._store.dispatch(push('/connect')); - this.connect(); + this.connect(host); }, 1000); }).catch(e => { log.error('Failed to log in,', e.message); @@ -224,9 +230,7 @@ export class Backend { log.debug('The stored account number still exists', accountData); this._store.dispatch(accountActions.loginSuccessful(accountData.expiry)); - - this._store.dispatch(push('/connect')); - this.connect(); + return this._store.dispatch(push('/connect')); }) .catch( e => { log.warn('Unable to autologin,', e.message); @@ -260,8 +264,7 @@ export class Backend { }); } - connect(aHost?: string): Promise<void> { - const host = aHost; + connect(host: string): Promise<void> { let setHostPromise = () => Promise.resolve(); if (host) { diff --git a/test/auth.spec.js b/test/auth.spec.js index c3fd78c83d..fa500bd8e3 100644 --- a/test/auth.spec.js +++ b/test/auth.spec.js @@ -29,7 +29,7 @@ describe('authentication', () => { const backend = new Backend(store, credentials, mockIpc); - backend.connect(); + backend.connect('example.com'); }); it('reauthenticates on reconnect', (done) => { @@ -48,7 +48,7 @@ describe('authentication', () => { }, done); - backend.connect(); + backend.connect('example.com'); checkNextTick(() => { expect(authCount).to.equal(1); }, done); diff --git a/test/helpers/ipc-helpers.js b/test/helpers/ipc-helpers.js index e2a578973b..2a2dd1e6b8 100644 --- a/test/helpers/ipc-helpers.js +++ b/test/helpers/ipc-helpers.js @@ -4,7 +4,7 @@ import { Backend } from '../../app/lib/backend'; import { newMockIpc } from '../mocks/ipc'; import configureStore from '../../app/redux/store'; import { createMemoryHistory } from 'history'; -import { mockState, mockStore } from '../mocks/redux'; +import { mockStore } from '../mocks/redux'; type DoneCallback = (?mixed) => void; type Check = () => void; @@ -32,7 +32,7 @@ export function setupBackendAndStore() { } export function setupBackendAndMockStore() { - const store = mockStore(mockState()); + const store = mockStore(_initialState()); const mockIpc = newMockIpc(); const credentials = { sharedSecret: '', @@ -42,6 +42,11 @@ export function setupBackendAndMockStore() { return { store, mockIpc, backend }; } +function _initialState() { + const { store } = setupIpcAndStore(); + return store.getState(); +} + // chai and async aren't the best of friends. To allow us // to get the assertion error in the output of failed async // tests we need to do this try-catch thing. diff --git a/test/mocks/redux.js b/test/mocks/redux.js index 71dafc7f1f..5f0562c035 100644 --- a/test/mocks/redux.js +++ b/test/mocks/redux.js @@ -1,27 +1,8 @@ import configureMockStore from 'redux-mock-store'; import thunk from 'redux-thunk'; -import { defaultServer } from '../../app/config'; const middlewares = [ thunk ]; export const mockStore = configureMockStore(middlewares); -export const mockState = () => { - return { - account: { - accountToken: null, - status: 'none', - error: null - }, - connection: { - status: 'disconnected', - serverAddress: null, - clientIp: null - }, - settings: { - autoSecure: false, - preferredServer: defaultServer - } - }; -}; export const filterMinorActions = (actions) => { return actions.filter((action) => { |
