use of com.nexblocks.authguard.api.dto.requests.CreateAccountRequestDTO in project AuthGuard by AuthGuard.
the class CreateAccountRequestValidatorTest method validateValidEmail.
@Test
void validateValidEmail() {
final CreateAccountRequestDTO request = CreateAccountRequestDTO.builder().externalId("external").email(AccountEmailDTO.builder().email("valid@valid.com").build()).domain("main").build();
final Validator<CreateAccountRequestDTO> validator = Validators.getForClass(CreateAccountRequestDTO.class);
final List<Violation> violations = validator.validate(request);
assertThat(violations).isEmpty();
}
use of com.nexblocks.authguard.api.dto.requests.CreateAccountRequestDTO in project AuthGuard by AuthGuard.
the class CreateAccountRequestValidatorTest method validateValidNoFields.
@Test
void validateValidNoFields() {
final CreateAccountRequestDTO request = CreateAccountRequestDTO.builder().domain("main").build();
final Validator<CreateAccountRequestDTO> validator = Validators.getForClass(CreateAccountRequestDTO.class);
final List<Violation> violations = validator.validate(request);
assertThat(violations).isEmpty();
}
use of com.nexblocks.authguard.api.dto.requests.CreateAccountRequestDTO in project AuthGuard by AuthGuard.
the class CreateAccountRequestValidatorTest method validateValidBackupEmail.
@Test
void validateValidBackupEmail() {
final CreateAccountRequestDTO request = CreateAccountRequestDTO.builder().externalId("external").backupEmail(AccountEmailDTO.builder().email("valid@valid.com").build()).domain("main").build();
final Validator<CreateAccountRequestDTO> validator = Validators.getForClass(CreateAccountRequestDTO.class);
final List<Violation> violations = validator.validate(request);
assertThat(violations).isEmpty();
}
use of com.nexblocks.authguard.api.dto.requests.CreateAccountRequestDTO in project AuthGuard by AuthGuard.
the class AccountsApiTest method create.
@Test
void create() {
final CreateAccountRequestDTO requestDTO = CreateAccountRequestDTO.builder().externalId("external").email(AccountEmailDTO.builder().email("email@server.com").build()).domain("main").build();
final RequestContextBO requestContext = RequestContextBO.builder().idempotentKey(UUID.randomUUID().toString()).build();
final AccountBO accountBO = mapper().toBO(requestDTO);
final AccountBO serviceResponse = accountBO.withId(UUID.randomUUID().toString());
Mockito.when(accountsService.create(Mockito.eq(accountBO), Mockito.any())).thenReturn(serviceResponse);
LOG.info("Request {}", requestDTO);
final ValidatableResponse httpResponse = given().body(requestDTO).contentType(ContentType.JSON).header(IdempotencyHeader.HEADER_NAME, requestContext.getIdempotentKey()).post(url()).then().statusCode(201).contentType(ContentType.JSON);
final AccountDTO response = httpResponse.extract().response().getBody().as(AccountDTO.class);
assertThat(response).isEqualToIgnoringGivenFields(requestDTO, "id", "deleted", "createdAt", "lastModified", "social", "identityProvider");
assertThat(response.getId()).isEqualTo(serviceResponse.getId());
}
use of com.nexblocks.authguard.api.dto.requests.CreateAccountRequestDTO in project AuthGuard by AuthGuard.
the class AccountsApiTest method createWithCredentials.
@Test
void createWithCredentials() {
final CreateAccountRequestDTO accountRequest = CreateAccountRequestDTO.builder().externalId("external").email(AccountEmailDTO.builder().email("email@server.com").build()).domain("main").build();
final CreateCredentialsRequestDTO credentialsRequest = CreateCredentialsRequestDTO.builder().plainPassword("password").addIdentifiers(UserIdentifierDTO.builder().identifier("username").type(UserIdentifier.Type.USERNAME).build()).build();
final CreateCompleteAccountRequestDTO completeRequest = CreateCompleteAccountRequestDTO.builder().account(accountRequest).credentials(credentialsRequest).build();
final RequestContextBO requestContext = RequestContextBO.builder().idempotentKey(UUID.randomUUID().toString()).build();
final AccountBO accountBO = mapper().toBO(accountRequest);
final AccountBO accountResponse = accountBO.withId(UUID.randomUUID().toString());
final CredentialsBO credentialsBO = mapper().toBO(credentialsRequest).withAccountId(accountResponse.getId());
final CredentialsBO credentialsResponse = credentialsBO.withId(UUID.randomUUID().toString());
Mockito.when(accountsService.create(Mockito.eq(accountBO), Mockito.any())).thenReturn(accountResponse);
Mockito.when(credentialsService.create(Mockito.eq(credentialsBO), Mockito.any())).thenReturn(credentialsResponse);
LOG.info("Request {}", accountRequest);
final ValidatableResponse httpResponse = given().body(completeRequest).contentType(ContentType.JSON).header(IdempotencyHeader.HEADER_NAME, requestContext.getIdempotentKey()).post(url("complete")).then().statusCode(201).contentType(ContentType.JSON);
final CreateCompleteAccountResponseDTO response = httpResponse.extract().response().getBody().as(CreateCompleteAccountResponseDTO.class);
assertThat(response.getAccountId()).isEqualTo(accountResponse.getId());
assertThat(response.getCredentialsId()).isEqualTo(credentialsResponse.getId());
}
Aggregations