Search in sources :

Example 1 with VerificationRequestBO

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");
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) AccountTokenDO(com.nexblocks.authguard.dal.model.AccountTokenDO) VerificationRequestBO(com.nexblocks.authguard.service.model.VerificationRequestBO) ImmutableEmail(com.nexblocks.authguard.external.email.ImmutableEmail) Test(org.junit.jupiter.api.Test)

Aggregations

AccountTokenDO (com.nexblocks.authguard.dal.model.AccountTokenDO)1 ImmutableEmail (com.nexblocks.authguard.external.email.ImmutableEmail)1 AccountBO (com.nexblocks.authguard.service.model.AccountBO)1 VerificationRequestBO (com.nexblocks.authguard.service.model.VerificationRequestBO)1 Test (org.junit.jupiter.api.Test)1