Skip to content
Snippets Groups Projects
Commit fdb2a3c7 authored by Shane Tomlinson's avatar Shane Tomlinson
Browse files

Merge pull request #1152 from fawek/issue-1123

Sync the e-mail list before attempting to remove an e-mail

close #1123
parents 86664caf 3920efde
No related branches found
No related tags found
No related merge requests found
......@@ -39,33 +39,37 @@ BrowserID.manageAccount = (function() {
}
function removeEmail(email, oncomplete) {
var emails = user.getStoredEmailKeypairs();
function complete() {
oncomplete && oncomplete();
}
if (_.size(emails) > 1) {
if (confirmAction("Remove " + email + " from your BrowserID?")) {
user.removeEmail(email, function() {
displayStoredEmails(oncomplete);
}, pageHelpers.getFailure(errors.removeEmail, oncomplete));
}
else {
complete();
user.syncEmails(function() {
var emails = user.getStoredEmailKeypairs();
if (!emails[email]) {
displayStoredEmails(oncomplete);
}
}
else {
if (confirmAction("Removing the last address will cancel your BrowserID account.\nAre you sure you want to continue?")) {
user.cancelUser(function() {
doc.location="/";
else if (_.size(emails) > 1) {
if (confirmAction("Remove " + email + " from your BrowserID?")) {
user.removeEmail(email, function() {
displayStoredEmails(oncomplete);
}, pageHelpers.getFailure(errors.removeEmail, oncomplete));
}
else {
complete();
}, pageHelpers.getFailure(errors.cancelUser, oncomplete));
}
}
else {
complete();
if (confirmAction("Removing the last address will cancel your BrowserID account.\nAre you sure you want to continue?")) {
user.cancelUser(function() {
doc.location="/";
complete();
}, pageHelpers.getFailure(errors.cancelUser, oncomplete));
}
else {
complete();
}
}
}
}, pageHelpers.getFailure(errors.syncEmails, oncomplete));
}
function displayEmails(emails) {
......
......@@ -68,7 +68,6 @@
bid.manageAccount(mocks, function() {
// switch to a single address return on the sync.
xhr.useResult("valid");
bid.manageAccount.removeEmail("testuser@testuser.com", function() {
equal($("#emailList").children().length, 1, "after removing an email, only one remains");
start();
......@@ -97,6 +96,25 @@
});
});
});
asyncTest("removeEmail doesn't cancel the account when removing a non-existent e-mail", function() {
bid.manageAccount(mocks, function() {
bid.manageAccount.removeEmail("non@existent.com", function() {
notEqual(mocks.document.location, "/", "redirection did not happen");
start();
});
});
});
asyncTest("removeEmail doesn't cancel the account when out of sync with the server", function() {
bid.manageAccount(mocks, function() {
xhr.useResult("multiple");
bid.manageAccount.removeEmail("testuser@testuser.com", function() {
notEqual(mocks.document.location, "/", "redirection did not happen");
start();
});
});
});
asyncTest("removeEmail with single email cancels account and XHR error", function() {
xhr.useResult("valid");
......
......@@ -70,6 +70,7 @@ BrowserID.Mocks.xhr = (function() {
"get /wsapi/have_email?email=unregistered%40testuser.com valid": { email_known: false },
"post /wsapi/remove_email valid": { success: true },
"post /wsapi/remove_email invalid": { success: false },
"post /wsapi/remove_email multiple": { success: true },
"post /wsapi/remove_email ajaxError": undefined,
"post /wsapi/account_cancel valid": { success: true },
"post /wsapi/account_cancel invalid": { success: false },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment