Minor: Make email check in '/email change' case-insensitive

This commit is contained in:
ljacqu 2017-10-28 13:10:02 +02:00
parent ba65633182
commit fbd8049af5
2 changed files with 24 additions and 2 deletions

View File

@ -47,7 +47,7 @@ public class AsyncChangeEmail implements AsynchronousProcess {
service.send(player, MessageKey.USAGE_ADD_EMAIL);
} else if (newEmail == null || !validationService.validateEmail(newEmail)) {
service.send(player, MessageKey.INVALID_NEW_EMAIL);
} else if (!oldEmail.equals(currentEmail)) {
} else if (!oldEmail.equalsIgnoreCase(currentEmail)) {
service.send(player, MessageKey.INVALID_OLD_EMAIL);
} else if (!validationService.isEmailFreeForRegistration(newEmail, player)) {
service.send(player, MessageKey.EMAIL_ALREADY_USED_ERROR);

View File

@ -45,7 +45,7 @@ public class AsyncChangeEmailTest {
private ValidationService validationService;
@Test
public void shouldAddEmail() {
public void shouldChangeEmail() {
// given
String newEmail = "new@mail.tld";
given(player.getName()).willReturn("Bobby");
@ -65,6 +65,28 @@ public class AsyncChangeEmailTest {
verify(service).send(player, MessageKey.EMAIL_CHANGED_SUCCESS);
}
@Test
public void shouldNotBeCaseSensitiveWhenComparingEmails() {
// given
String newEmail = "newmail@example.com";
given(player.getName()).willReturn("Debra");
given(playerCache.isAuthenticated("debra")).willReturn(true);
String oldEmail = "OLD-mail@example.org";
PlayerAuth auth = authWithMail(oldEmail);
given(playerCache.getAuth("debra")).willReturn(auth);
given(dataSource.updateEmail(auth)).willReturn(true);
given(validationService.validateEmail(newEmail)).willReturn(true);
given(validationService.isEmailFreeForRegistration(newEmail, player)).willReturn(true);
// when
process.changeEmail(player, "old-mail@example.org", newEmail);
// then
verify(dataSource).updateEmail(auth);
verify(playerCache).updatePlayer(auth);
verify(service).send(player, MessageKey.EMAIL_CHANGED_SUCCESS);
}
@Test
public void shouldShowErrorIfSaveFails() {
// given