Ivan - Update user store tests [skip ci]

This commit is contained in:
ivan 2016-08-01 14:48:08 -03:00
parent 8952c1b7e1
commit db32a2a6ab
2 changed files with 90 additions and 2 deletions

View File

@ -9,6 +9,7 @@ const Message = React.createClass({
propTypes: { propTypes: {
title: React.PropTypes.string, title: React.PropTypes.string,
children: React.PropTypes.node, children: React.PropTypes.node,
leftAligned: React.PropTypes.bool,
type: React.PropTypes.oneOf(['success', 'error', 'info']) type: React.PropTypes.oneOf(['success', 'error', 'info'])
}, },

View File

@ -198,5 +198,92 @@ describe('UserStore', function () {
}); });
}); });
}); });
}}) }});
describe('when recovering password', function () {
beforeEach(function () {
let mockSuccessData = {
status: 'success',
data: {}
};
API.call = stub().returns({
then: (resolve) => {resolve(mockSuccessData)}
});
spy(UserStore, 'trigger');
});
afterEach(function () {
UserStore.trigger.restore();
});
it('should send recover password', function () {
UserStore.sendRecoverPassword({
email: 'SOME_EMAIL'
});
expect(API.call).to.have.been.calledWithMatch({
path: 'user/send-recover-password',
data: {
email: 'SOME_EMAIL'
}
});
expect(UserStore.trigger).to.have.been.calledWith('SEND_RECOVER_SUCCESS');
});
it('should trigger fail if send recover fails', function () {
API.call = stub().returns({
then: (resolve, reject) => {reject({ status: 'fail'})}
});
UserStore.sendRecoverPassword({
email: 'SOME_EMAIL'
});
expect(API.call).to.have.been.calledWithMatch({
path: 'user/send-recover-password',
data: {
email: 'SOME_EMAIL'
}
});
expect(UserStore.trigger).to.have.been.calledWith('SEND_RECOVER_FAIL');
});
it('should recover password', function () {
UserStore.recoverPassword({
email: 'SOME_EMAIL',
token: 'SOME_TOKEN',
password: 'SOME_PASSWORD'
});
expect(API.call).to.have.been.calledWithMatch({
path: 'user/recover-password',
data: {
email: 'SOME_EMAIL',
token: 'SOME_TOKEN',
password: 'SOME_PASSWORD'
}
});
expect(UserStore.trigger).to.have.been.calledWith('VALID_RECOVER');
});
it('should trigger fail if recover password fails', function () {
API.call = stub().returns({
then: (resolve, reject) => {reject({ status: 'fail'})}
});
UserStore.recoverPassword({
email: 'SOME_EMAIL',
token: 'SOME_TOKEN',
password: 'SOME_PASSWORD'
});
expect(API.call).to.have.been.calledWithMatch({
path: 'user/recover-password',
data: {
email: 'SOME_EMAIL',
token: 'SOME_TOKEN',
password: 'SOME_PASSWORD'
}
});
expect(UserStore.trigger).to.have.been.calledWith('INVALID_RECOVER');
});
});
}); });