diff options
| author | Erik Larkö <erik@mullvad.net> | 2017-07-04 13:12:18 +0200 |
|---|---|---|
| committer | Erik Larkö <erik@mullvad.net> | 2017-07-05 17:02:17 +0200 |
| commit | 91e50b1c4eaec737944cb9d56d6d2e99749edcdd (patch) | |
| tree | 13da723f884618c570f5dc1d115a3b47e42306f9 /test | |
| parent | 2abc1f10caf3862e8b1cbc7ebdeef545c90d4a26 (diff) | |
| download | mullvadvpn-91e50b1c4eaec737944cb9d56d6d2e99749edcdd.tar.xz mullvadvpn-91e50b1c4eaec737944cb9d56d6d2e99749edcdd.zip | |
Logout tests
Diffstat (limited to 'test')
| -rw-r--r-- | test/helpers/ipc-helpers.js | 5 | ||||
| -rw-r--r-- | test/logout.spec.js | 65 |
2 files changed, 70 insertions, 0 deletions
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); + }); +}); |
