summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--app/lib/backend.js15
-rw-r--r--test/helpers/ipc-helpers.js5
-rw-r--r--test/logout.spec.js65
3 files changed, 82 insertions, 3 deletions
diff --git a/app/lib/backend.js b/app/lib/backend.js
index a4487f56a6..b4ac1c2574 100644
--- a/app/lib/backend.js
+++ b/app/lib/backend.js
@@ -198,8 +198,17 @@ export class Backend {
// emit event
this._emit('logout');
+ this._store.dispatch(accountActions.loginChange({
+ status: 'none',
+ accountNumber: null,
+ paidUntil: null,
+ }));
+
// disconnect user during logout
- return this.disconnect();
+ return this.disconnect()
+ .then( () => {
+ this._store.dispatch(push('/'));
+ });
})
.catch(e => {
log.info('Failed to logout', e);
@@ -238,9 +247,9 @@ export class Backend {
});
}
- disconnect() {
+ disconnect(): Promise<void> {
// @TODO: Failure modes
- this._ipc.disconnect()
+ return this._ipc.disconnect()
.then(() => {
// emit: disconnect
this._emit('disconnect');
diff --git a/test/helpers/ipc-helpers.js b/test/helpers/ipc-helpers.js
index bffc6b1540..b32c1e5b69 100644
--- a/test/helpers/ipc-helpers.js
+++ b/test/helpers/ipc-helpers.js
@@ -66,6 +66,11 @@ export function failFast(fn: Check, done: DoneCallback) {
done(e);
}
}
+export function failFastNextTick(fn: Check, done: DoneCallback) {
+ setTimeout(() => {
+ failFast(fn, done);
+ }, 1);
+}
type MockStore = {
getActions: () => Array<{type: string, payload: Object}>,
diff --git a/test/logout.spec.js b/test/logout.spec.js
new file mode 100644
index 0000000000..c3f51e6c4f
--- /dev/null
+++ b/test/logout.spec.js
@@ -0,0 +1,65 @@
+// @flow
+
+import { expect } from 'chai';
+import { setupBackendAndStore, setupBackendAndMockStore, getLocation, checkNextTick, failFastNextTick } from './helpers/ipc-helpers';
+import { IpcChain } from './helpers/IpcChain';
+import accountActions from '../app/redux/account/actions';
+
+describe('logging out', () => {
+
+ it('should set the account to the empty string and then disconnect', (done) => {
+ const { mockIpc, backend } = setupBackendAndStore();
+
+ const chain = new IpcChain(mockIpc, done);
+ chain.addRequiredStep('setAccount')
+ .withInputValidation((num) => {
+ expect(num).to.equal('');
+ })
+ .done();
+ chain.addRequiredStep('disconnect')
+ .done();
+
+ backend.logout();
+ });
+
+
+ it('should remove the account number from the store', (done) => {
+
+ const { store, backend, mockIpc } = setupBackendAndStore();
+ mockIpc.getAccountData = () => new Promise(r => r({
+ paid_until: '2001-01-01T00:00:00',
+ }));
+ const action: any = accountActions.login(backend, '123');
+ store.dispatch(action);
+
+ const expectedLogoutState = {
+ status: 'none',
+ accountNumber: null,
+ paidUntil: null,
+ error: null,
+ };
+
+ failFastNextTick(() => {
+ let state = store.getState().account;
+ expect(state).not.to.include(expectedLogoutState);
+
+ backend.logout();
+
+ checkNextTick(() => {
+ state = store.getState().account;
+ expect(state).to.include(expectedLogoutState);
+ }, done);
+ }, done);
+ });
+
+
+ it('should redirect to / on logout', (done) => {
+ const { store, backend } = setupBackendAndMockStore();
+
+ backend.logout();
+
+ checkNextTick(() => {
+ expect(getLocation(store)).to.equal('/');
+ }, done);
+ });
+});