summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@codeispoetry.ru>2017-02-14 15:57:35 +0000
committerAndrej Mihajlov <and@codeispoetry.ru>2017-02-14 15:57:35 +0000
commitaf6e1ecd9051ecb590cb189de37978d366da6cdd (patch)
tree094181fa45f3a9a50adc2fa59e7cb7e7095a751d /test
parentd9725c147e491d539417b9441ea4785806ab9f66 (diff)
downloadmullvadvpn-af6e1ecd9051ecb590cb189de37978d366da6cdd.tar.xz
mullvadvpn-af6e1ecd9051ecb590cb189de37978d366da6cdd.zip
Add tests for login action
Diffstat (limited to 'test')
-rw-r--r--test/actions/user.spec.js69
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);
+ });
+
});
});