diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/actions/user.spec.js | 69 |
1 files changed, 68 insertions, 1 deletions
diff --git a/test/actions/user.spec.js b/test/actions/user.spec.js index 91f0b8b125..259e862a6d 100644 --- a/test/actions/user.spec.js +++ b/test/actions/user.spec.js @@ -1,7 +1,10 @@ -import { expect } from 'chai'; +import chai, { expect } from 'chai'; +import spy from 'chai-spies'; import actions from '../../app/actions/user'; import { LoginState } from '../../app/constants'; +chai.use(spy); + describe('actions', () => { describe('user', () => { @@ -19,5 +22,69 @@ describe('actions', () => { expect(actions.loginChange(payload)).to.deep.equal(test); }); + it('should successfully login', (done) => { + const actionType = actions.loginChange.toString(); + const account = '1234'; + const getState = () => ({}); + let callCounter = 0; + const dispatch = chai.spy((action) => { + callCounter += 1; + + if(callCounter == 2) { + expect(dispatch).to.have.been.called.with({ + type: actionType, + payload: { account, status: LoginState.connecting } + }); + + expect(dispatch).to.have.been.called.with({ + type: actionType, + payload: { status: LoginState.ok } + }); + + done(); + } + }); + + const backend = { + login: () => Promise.resolve() + }; + + const action = actions.login(backend, account); + + action(dispatch, getState); + }); + + it('should fail login', (done) => { + const actionType = actions.loginChange.toString(); + const account = '1234'; + const getState = () => ({}); + let callCounter = 0; + const dispatch = chai.spy((action) => { + callCounter += 1; + + if(callCounter == 2) { + expect(dispatch).to.have.been.called.with({ + type: actionType, + payload: { account, status: LoginState.connecting } + }); + + expect(dispatch).to.have.been.called.with({ + type: actionType, + payload: { status: LoginState.failed, error: new Error('Failed') } + }); + + done(); + } + }); + + const backend = { + login: () => Promise.reject(new Error('Failed')) + }; + + const action = actions.login(backend, account); + + action(dispatch, getState); + }); + }); }); |
