use of com.nexblocks.authguard.external.email.ImmutableEmail in project AuthGuard by AuthGuard.
the class EmailPasswordlessSubscriberTest method onValidMessage.
@Test
void onValidMessage() {
final AccountTokenDO accountToken = AccountTokenDO.builder().token("token").build();
final AccountBO account = AccountBO.builder().email(AccountEmailBO.builder().email("user@test.net").build()).firstName("first").lastName("second").build();
final PasswordlessMessageBody messageBody = new PasswordlessMessageBody(accountToken, account);
final Message message = Messages.passwordlessGenerated(messageBody);
final ImmutableEmail expectedEmail = ImmutableEmail.builder().template("passwordless").to(account.getEmail().getEmail()).parameters(ImmutableMap.of("token", accountToken.getToken(), "firstName", account.getFirstName(), "lastName", account.getLastName())).build();
emailPasswordlessSubscriber.onMessage(message);
final ArgumentCaptor<ImmutableEmail> sentEmailCaptor = ArgumentCaptor.forClass(ImmutableEmail.class);
Mockito.verify(emailProvider).send(sentEmailCaptor.capture());
assertThat(sentEmailCaptor.getValue()).isEqualTo(expectedEmail);
}
use of com.nexblocks.authguard.external.email.ImmutableEmail in project AuthGuard by AuthGuard.
the class EmailResetTokenSubscriberTest method onValidMessage.
@Test
void onValidMessage() {
final AccountTokenDO accountToken = AccountTokenDO.builder().token("token").build();
final AccountBO account = AccountBO.builder().email(AccountEmailBO.builder().email("user@test.net").build()).firstName("first").lastName("second").build();
final ResetTokenMessage messageBody = new ResetTokenMessage(account, accountToken);
final Message message = Messages.resetTokenGenerated(messageBody);
final ImmutableEmail expectedEmail = ImmutableEmail.builder().template("passwordReset").to(account.getEmail().getEmail()).parameters(ImmutableMap.of("token", accountToken.getToken(), "firstName", account.getFirstName(), "lastName", account.getLastName())).build();
emailResetTokenSubscriber.onMessage(message);
final ArgumentCaptor<ImmutableEmail> sentEmailCaptor = ArgumentCaptor.forClass(ImmutableEmail.class);
Mockito.verify(emailProvider).send(sentEmailCaptor.capture());
assertThat(sentEmailCaptor.getValue()).isEqualTo(expectedEmail);
}
use of com.nexblocks.authguard.external.email.ImmutableEmail in project AuthGuard by AuthGuard.
the class VerificationSubscriber method doSendEmails.
private void doSendEmails(final VerificationRequestBO verificationRequest) {
final AccountBO account = verificationRequest.getAccount();
verificationRequest.getEmails().forEach(email -> {
if (email == null) {
LOG.warn("Email is null. Skipping.");
} else if (email.isVerified()) {
LOG.warn("Email is already verified. Skipping.");
} else {
final String token = generateVerificationString();
final AccountTokenDO accountToken = AccountTokenDO.builder().expiresAt(OffsetDateTime.now().plus(tokenTtl)).associatedAccountId(account.getId()).token(token).additionalInformation(Collections.singletonMap("email", email.getEmail())).build();
accountTokensRepository.save(accountToken);
final ImmutableEmail email1 = ImmutableEmail.builder().template(EMAIL_TEMPLATE).to(email.getEmail()).putParameters("token", token).build();
emailProvider.send(email1);
LOG.info("Sent a verification email");
}
});
}
Aggregations