summaryrefslogtreecommitdiffhomepage
path: root/test/logout.spec.js
blob: c3f51e6c4f5de2d52fedcf321f59daf9424ba098 (plain)
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
// @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);
  });
});