#437 Add/change email should check if email is already used

- Untested/incomplete implementation
This commit is contained in:
ljacqu
2016-01-17 20:41:19 +01:00
parent ace95f750a
commit b0ba893827
11 changed files with 105 additions and 177 deletions
@@ -53,6 +53,7 @@ public class AsyncAddEmailTest {
PlayerAuth auth = mock(PlayerAuth.class);
given(auth.getEmail()).willReturn(null);
given(playerCache.getAuth("tester")).willReturn(auth);
given(dataSource.isEmailStored("my.mail@example.org")).willReturn(false);
// when
process.process();
@@ -72,6 +73,7 @@ public class AsyncAddEmailTest {
PlayerAuth auth = mock(PlayerAuth.class);
given(auth.getEmail()).willReturn("another@mail.tld");
given(playerCache.getAuth("my_player")).willReturn(auth);
given(dataSource.isEmailStored("some.mail@example.org")).willReturn(false);
// when
process.process();
@@ -90,6 +92,7 @@ public class AsyncAddEmailTest {
PlayerAuth auth = mock(PlayerAuth.class);
given(auth.getEmail()).willReturn(null);
given(playerCache.getAuth("my_player")).willReturn(auth);
given(dataSource.isEmailStored("invalid_mail")).willReturn(false);
// when
process.process();
@@ -99,6 +102,25 @@ public class AsyncAddEmailTest {
verify(playerCache, never()).updatePlayer(any(PlayerAuth.class));
}
@Test
public void shouldNotAddMailIfAlreadyUsed() {
// given
AsyncAddEmail process = createProcess("player@mail.tld");
given(player.getName()).willReturn("TestName");
given(playerCache.isAuthenticated("testname")).willReturn(true);
PlayerAuth auth = mock(PlayerAuth.class);
given(auth.getEmail()).willReturn(null);
given(playerCache.getAuth("testname")).willReturn(auth);
given(dataSource.isEmailStored("player@mail.tld")).willReturn(true);
// when
process.process();
// then
verify(messages).send(player, MessageKey.EMAIL_ALREADY_USED_ERROR);
verify(playerCache, never()).updatePlayer(any(PlayerAuth.class));
}
@Test
public void shouldShowLoginMessage() {
// given
@@ -136,6 +136,25 @@ public class AsyncChangeEmailTest {
verify(messages).send(player, MessageKey.INVALID_OLD_EMAIL);
}
@Test
public void shouldRejectAlreadyUsedEmail() {
// given
AsyncChangeEmail process = createProcess("old@example.com", "new@example.com");
given(player.getName()).willReturn("Username");
given(playerCache.isAuthenticated("username")).willReturn(true);
PlayerAuth auth = authWithMail("old@example.com");
given(playerCache.getAuth("username")).willReturn(auth);
given(dataSource.isEmailStored("new@example.com")).willReturn(true);
// when
process.process();
// then
verify(dataSource, never()).updateEmail(any(PlayerAuth.class));
verify(playerCache, never()).updatePlayer(any(PlayerAuth.class));
verify(messages).send(player, MessageKey.EMAIL_ALREADY_USED_ERROR);
}
@Test
public void shouldSendLoginMessage() {
// given