use of org.haiku.haikudepotserver.api1.model.user.InitiatePasswordResetRequest in project haikudepotserver by haiku.
the class UserApiIT method testInitiatePasswordReset.
/**
* <p>This test will check the initiation of the password reset procedure.</p>
*/
@Test
public void testInitiatePasswordReset() {
createPasswordResetTestUser();
Captcha captcha = captchaService.generate();
InitiatePasswordResetRequest request = new InitiatePasswordResetRequest();
request.captchaToken = captcha.getToken();
request.captchaResponse = captcha.getResponse();
request.email = "integration-test-recipient@haiku-os.org";
// ------------------------------------
userApi.initiatePasswordReset(request);
// ------------------------------------
{
ObjectContext context = serverRuntime.newContext();
User user = User.tryGetByNickname(context, "testuser").get();
// check for the presence of a token.
List<UserPasswordResetToken> tokens = UserPasswordResetToken.findByUser(context, user);
Assertions.assertThat(tokens.size()).isEqualTo(1);
UserPasswordResetToken token = tokens.get(0);
// check that an email did actually get sent.
List<SimpleMailMessage> messages = mailSender.getSentMessages();
Assertions.assertThat(messages.size()).isEqualTo(1);
SimpleMailMessage message = messages.get(0);
Assertions.assertThat(message.getTo()).isEqualTo(new String[] { "integration-test-recipient@haiku-os.org" });
Assertions.assertThat(message.getFrom()).isEqualTo("integration-test-sender@haiku-os.org");
Assertions.assertThat(message.getText()).contains(token.getCode());
}
}
Aggregations