diff options
| -rw-r--r-- | package.json | 1 | ||||
| -rw-r--r-- | test/actions/user.spec.js | 69 |
2 files changed, 69 insertions, 1 deletions
diff --git a/package.json b/package.json index 4001a7c02f..612103bf91 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "babel-preset-stage-0": "^6.1.18", "browser-sync": "^2.9.3", "chai": "^3.4.1", + "chai-spies": "^0.7.1", "electron": "^1.5.0", "electron-builder": "^12.3.1", "electron-devtools-installer": "^2.1.0", 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); + }); + }); }); |
