use of com.nexblocks.authguard.service.model.VerificationRequestBO in project AuthGuard by AuthGuard.
the class VerificationSubscriberTest method onMessage.
@Test
void onMessage() {
final AccountBO account = AccountBO.builder().id("account-id").email(AccountEmailBO.builder().email("unverified").verified(false).build()).build();
final VerificationRequestBO verificationRequest = VerificationRequestBO.builder().account(account).emails(Collections.singletonList(account.getEmail())).build();
final Message<VerificationRequestBO> message = Message.<VerificationRequestBO>builder().eventType(EventType.EMAIL_VERIFICATION).bodyType(VerificationRequestBO.class).messageBody(verificationRequest).build();
verificationSubscriber.onMessage(message);
final ArgumentCaptor<AccountTokenDO> accountTokenCaptor = ArgumentCaptor.forClass(AccountTokenDO.class);
final ArgumentCaptor<ImmutableEmail> emailCaptor = ArgumentCaptor.forClass(ImmutableEmail.class);
Mockito.verify(accountTokensRepository).save(accountTokenCaptor.capture());
Mockito.verify(emailProvider, Mockito.times(1)).send(emailCaptor.capture());
final AccountTokenDO accountToken = accountTokenCaptor.getValue();
final ImmutableEmail email = emailCaptor.getValue();
assertThat(accountToken.getAssociatedAccountId()).isEqualTo(account.getId());
assertThat(accountToken.getAdditionalInformation().get("email")).isEqualTo("unverified");
assertThat(accountToken.getToken()).isNotNull();
assertThat(accountToken.getExpiresAt()).isNotNull();
assertThat(email.getTo()).isEqualTo("unverified");
assertThat(email.getBody()).isNull();
assertThat(email.getParameters()).containsOnlyKeys("token");
}
Aggregations