1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
// @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 null and then disconnect', (done) => {
const { mockIpc, backend } = setupBackendAndStore();
const chain = new IpcChain(mockIpc);
chain.require('setAccount')
.withInputValidation((num) => {
expect(num).to.be.null;
})
.done();
chain.require('disconnect')
.done();
chain.onSuccessOrFailure(done);
backend.logout();
});
it('should remove the account number from the store', (done) => {
const { store, backend, mockIpc } = setupBackendAndStore();
mockIpc.getAccountData = () => new Promise(r => r({
expiry: '2001-01-01T00:00:00.000Z',
}));
const action: any = accountActions.login(backend, '123');
store.dispatch(action);
const expectedLogoutState = {
status: 'none',
accountToken: null,
expiry: 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);
});
});
|