Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
fix(email): add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vbudhram committed Sep 25, 2018
1 parent cbac5f1 commit cd70117
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 7 deletions.
4 changes: 3 additions & 1 deletion app/scripts/models/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -1446,9 +1446,10 @@ const Account = Backbone.Model.extend({
* @param {String} recoveryKeyId - recoveryKeyId that maps to recovery key
* @param {String} kB - original kB
* @param {Object} relier - relier being signed in to.
* @param {String} emailToHashWith - has password with this email address
* @returns {Promise} resolves with response when complete.
*/
resetPasswordWithRecoveryKey(accountResetToken, password, recoveryKeyId, kB, relier) {
resetPasswordWithRecoveryKey(accountResetToken, password, recoveryKeyId, kB, relier, emailToHashWith) {
return this._fxaClient.resetPasswordWithRecoveryKey(
accountResetToken,
this.get('email'),
Expand All @@ -1457,6 +1458,7 @@ const Account = Backbone.Model.extend({
kB,
relier,
{
emailToHashWith,
metricsContext: this._metrics.getFlowEventMetadata()
})
.then(this.set.bind(this));
Expand Down
5 changes: 3 additions & 2 deletions app/scripts/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,10 +636,11 @@ define(function (require, exports, module) {
* @param {String} recoveryKeyId - recoveryKeyId that maps to recovery code
* @param {String} kB - original kB
* @param {Object} relier - relier being signed in to
* @param {String} emailToHashWith - hash password with this email
* @returns {Promise} - resolves when complete
*/
completeAccountPasswordResetWithRecoveryKey (account, password, accountResetToken, recoveryKeyId, kB, relier) {
return account.resetPasswordWithRecoveryKey(accountResetToken, password, recoveryKeyId, kB, relier)
completeAccountPasswordResetWithRecoveryKey (account, password, accountResetToken, recoveryKeyId, kB, relier, emailToHashWith) {
return account.resetPasswordWithRecoveryKey(accountResetToken, password, recoveryKeyId, kB, relier, emailToHashWith)
.then(() => {
this._notifyOfAccountSignIn(account);
return this.setSignedInAccount(account);
Expand Down
3 changes: 2 additions & 1 deletion app/scripts/views/complete_reset_password.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ define(function (require, exports, module) {
accountRecoveryVerificationInfo.get('accountResetToken'),
accountRecoveryVerificationInfo.get('recoveryKeyId'),
accountRecoveryVerificationInfo.get('kB'),
this.relier);
this.relier,
emailToHashWith);
}

return this.user.completeAccountPasswordReset(
Expand Down
46 changes: 44 additions & 2 deletions app/tests/spec/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -1152,15 +1152,16 @@ define(function (require, exports, module) {
sinon.spy(notifier, 'triggerRemote');

return user.completeAccountPasswordReset(
account, 'password', 'token', 'code', relierMock);
account, 'password', 'token', 'code', relierMock, EMAIL);
});

it('delegates to the account', function () {
assert.isTrue(account.completePasswordReset.calledWith(
'password',
'token',
'code',
relierMock
relierMock,
EMAIL
));
});

Expand All @@ -1173,6 +1174,47 @@ define(function (require, exports, module) {
});
});

describe('completeAccountPasswordResetWithRecoveryKey', () => {
let account;
const relierMock = {};
const recoveryKeyId = 'recoveryKeyId';
const kB = 'kB';

beforeEach(() => {
account = user.initAccount({
email: EMAIL,
sessionToken: 'sessionToken',
sessionTokenContext: 'sessionTokenContext',
uid: createUid()
});

sinon.stub(account, 'resetPasswordWithRecoveryKey').callsFake(() => Promise.resolve());
sinon.stub(user, 'setSignedInAccount').callsFake((account) => Promise.resolve(account));
sinon.spy(notifier, 'triggerRemote');

return user.completeAccountPasswordResetWithRecoveryKey(account, 'password', 'token', recoveryKeyId, kB, relierMock, EMAIL);
});

it('delegates to the account', () => {
assert.isTrue(account.resetPasswordWithRecoveryKey.calledWith(
'token',
'password',
recoveryKeyId,
kB,
relierMock,
EMAIL
));
});

it('saves the updated account data', () => {
assert.isTrue(user.setSignedInAccount.calledWith(account));
});

it('notifies remote listeners', () => {
testRemoteSignInMessageSent(account);
});
});

describe('pickResumeTokenInfo', function () {
it('returns the uniqueUserId', function () {
var resumeTokenInfo = user.pickResumeTokenInfo();
Expand Down
43 changes: 42 additions & 1 deletion tests/functional/settings_change_email.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ registerSuite('settings change email', {

'can change primary email, change password, login, change email and login': function () {
return this.remote
// change password
// change password
.then(click(selectors.CHANGE_PASSWORD.MENU_BUTTON))
.then(fillOutChangePassword(PASSWORD, NEW_PASSWORD))

Expand All @@ -173,6 +173,47 @@ registerSuite('settings change email', {
.then(fillOutSignIn(email, NEW_PASSWORD))
.then(testElementExists(selectors.SETTINGS.HEADER));
},

'can change primary email, reset password, login, change email and login': function () {
return this.remote
.then(click(selectors.SETTINGS.SIGNOUT))
.then(testElementExists(selectors.SIGNIN.HEADER))

.then(click(selectors.CHANGE_PASSWORD.LINK_RESET_PASSWORD))

.then(fillOutResetPassword(secondaryEmail))
.then(testElementExists(selectors.CONFIRM_RESET_PASSWORD.HEADER))

// user browses to another site.
.then(openVerificationLinkInNewTab(secondaryEmail, 2))

.then(switchToWindow(1))

.then(fillOutCompleteResetPassword(NEW_PASSWORD, NEW_PASSWORD))
.then(testElementExists(selectors.SETTINGS.HEADER))
.then(testSuccessWasShown())

// switch to the original window
.then(closeCurrentWindow())

// sign in with new password
.then(click(selectors.SETTINGS.SIGNOUT))
.then(openPage(SIGNIN_URL, selectors.SIGNIN.HEADER))
.then(fillOutSignIn(secondaryEmail, NEW_PASSWORD))
.then(testElementTextEquals(selectors.SETTINGS.PROFILE_HEADER, secondaryEmail))

// set primary email to original email
.then(click(selectors.EMAIL.MENU_BUTTON))
.then(testElementTextEquals(selectors.EMAIL.ADDRESS_LABEL, email))
.then(testElementExists(selectors.EMAIL.VERIFIED_LABEL))
.then(click(selectors.EMAIL.SET_PRIMARY_EMAIL_BUTTON))

// sign out and login with new password
.then(click(selectors.SETTINGS.SIGNOUT))
.then(testElementExists(selectors.SIGNIN.HEADER))
.then(fillOutSignIn(email, NEW_PASSWORD))
.then(testElementExists(selectors.SETTINGS.HEADER));
},
}
});

Expand Down

0 comments on commit cd70117

Please sign in to comment.