Search in sources :

Example 1 with CreateUserRequest

use of uk.gov.pay.adminusers.model.CreateUserRequest in project pay-adminusers by alphagov.

the class UserCreatorTest method shouldSaveAndReturnUser_forValidUserCreationRequest.

@Test
public void shouldSaveAndReturnUser_forValidUserCreationRequest() {
    String validRole = "validRole";
    when(mockRoleDao.findByRoleName(validRole)).thenReturn(Optional.of(mock(RoleEntity.class)));
    CreateUserRequest request = CreateUserRequest.from("email@example.com", "password", "email@example.com", null, null, "otpKey", "3745838475", null);
    User user = userCreator.doCreate(request, validRole);
    verify(mockUserDao).persist(expectedUser.capture());
    assertThat(expectedUser.getValue().getEmail(), is("email@example.com"));
    assertThat(user.getEmail(), is("email@example.com"));
    assertThat(user.getSecondFactor(), is(SecondFactorMethod.SMS));
    assertThat(user.getServiceRoles().size(), is(0));
}
Also used : User(uk.gov.pay.adminusers.model.User) CreateUserRequest(uk.gov.pay.adminusers.model.CreateUserRequest) Test(org.junit.jupiter.api.Test)

Example 2 with CreateUserRequest

use of uk.gov.pay.adminusers.model.CreateUserRequest in project pay-adminusers by alphagov.

the class UserCreatorTest method shouldError_ifRoleIsInvalid.

@Test
public void shouldError_ifRoleIsInvalid() {
    String validRole = "inValidRole";
    when(mockRoleDao.findByRoleName(validRole)).thenReturn(Optional.empty());
    CreateUserRequest request = CreateUserRequest.from("email@example.com", "password", "email@example.com", null, null, "otpKey", "3745838475", null);
    WebApplicationException exception = assertThrows(WebApplicationException.class, () -> userCreator.doCreate(request, validRole));
    assertThat(exception.getMessage(), is("HTTP 400 Bad Request"));
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) CreateUserRequest(uk.gov.pay.adminusers.model.CreateUserRequest) Test(org.junit.jupiter.api.Test)

Example 3 with CreateUserRequest

use of uk.gov.pay.adminusers.model.CreateUserRequest in project pay-adminusers by alphagov.

the class UserCreatorTest method shouldSaveAndReturnUser_forValidUserCreationRequest_withGatewayAccountIds.

@Test
public void shouldSaveAndReturnUser_forValidUserCreationRequest_withGatewayAccountIds() {
    String validRole = "validRole";
    when(mockRoleDao.findByRoleName(validRole)).thenReturn(Optional.of(mock(RoleEntity.class)));
    CreateUserRequest request = CreateUserRequest.from("email@example.com", "password", "email@example.com", asList("1", "2"), null, "otpKey", "3745838475", null);
    User user = userCreator.doCreate(request, validRole);
    verify(mockUserDao).persist(expectedUser.capture());
    assertThat(expectedUser.getValue().getEmail(), is("email@example.com"));
    assertThat(user.getEmail(), is("email@example.com"));
    assertThat(user.getSecondFactor(), is(SecondFactorMethod.SMS));
    assertThat(user.getServiceRoles().size(), is(1));
    ArgumentCaptor<ServiceEntity> serviceEntityArgumentCaptor = ArgumentCaptor.forClass(ServiceEntity.class);
    verify(mockServiceDao).persist(serviceEntityArgumentCaptor.capture());
    ServiceEntity serviceEntity = serviceEntityArgumentCaptor.getValue();
    assertThat(serviceEntity.getServiceNames().get(SupportedLanguage.ENGLISH).getName(), is(Service.DEFAULT_NAME_VALUE));
    assertThat(serviceEntity.getGatewayAccountIds().get(0).getGatewayAccountId(), is("1"));
    assertThat(serviceEntity.getGatewayAccountIds().get(1).getGatewayAccountId(), is("2"));
    Service service = user.getServiceRoles().get(0).getService();
    assertThat(service.getName(), is(Service.DEFAULT_NAME_VALUE));
    assertThat(service.getServiceNames().get(SupportedLanguage.ENGLISH.toString()), is(Service.DEFAULT_NAME_VALUE));
    assertThat(service.getGatewayAccountIds(), is(asList("1", "2")));
    assertThat(service.isRedirectToServiceImmediatelyOnTerminalState(), is(false));
    assertThat(service.isCollectBillingAddress(), is(true));
    assertThat(service.getDefaultBillingAddressCountry(), is("GB"));
}
Also used : User(uk.gov.pay.adminusers.model.User) ServiceEntity(uk.gov.pay.adminusers.persistence.entity.ServiceEntity) Service(uk.gov.pay.adminusers.model.Service) CreateUserRequest(uk.gov.pay.adminusers.model.CreateUserRequest) Test(org.junit.jupiter.api.Test)

Example 4 with CreateUserRequest

use of uk.gov.pay.adminusers.model.CreateUserRequest in project pay-adminusers by alphagov.

the class UserCreatorTest method shouldSaveAndReturnUser_forValidUserCreationRequest_withServiceRoles_evenIfSomeExternalIdsMissing.

@Test
public void shouldSaveAndReturnUser_forValidUserCreationRequest_withServiceRoles_evenIfSomeExternalIdsMissing() {
    String validRole = "validRole";
    when(mockRoleDao.findByRoleName(validRole)).thenReturn(Optional.of(mock(RoleEntity.class)));
    CreateUserRequest request = CreateUserRequest.from("email@example.com", "password", "email@example.com", null, asList("ext-id-1", "ext-id-2"), "otpKey", "3745838475", null);
    when(mockServiceDao.findByExternalId("ext-id-1")).thenReturn(Optional.of(mock(ServiceEntity.class)));
    when(mockServiceDao.findByExternalId("ext-id-2")).thenReturn(Optional.empty());
    User user = userCreator.doCreate(request, validRole);
    verify(mockUserDao).persist(expectedUser.capture());
    assertThat(expectedUser.getValue().getEmail(), is("email@example.com"));
    assertThat(user.getEmail(), is("email@example.com"));
    assertThat(user.getSecondFactor(), is(SecondFactorMethod.SMS));
    assertThat(user.getServiceRoles().size(), is(1));
}
Also used : User(uk.gov.pay.adminusers.model.User) CreateUserRequest(uk.gov.pay.adminusers.model.CreateUserRequest) Test(org.junit.jupiter.api.Test)

Example 5 with CreateUserRequest

use of uk.gov.pay.adminusers.model.CreateUserRequest in project pay-adminusers by alphagov.

the class UserCreatorTest method shouldSaveAndReturnUser_forValidUserCreationRequest_withServiceRoles.

@Test
public void shouldSaveAndReturnUser_forValidUserCreationRequest_withServiceRoles() {
    String validRole = "validRole";
    when(mockRoleDao.findByRoleName(validRole)).thenReturn(Optional.of(mock(RoleEntity.class)));
    CreateUserRequest request = CreateUserRequest.from("email@example.com", "password", "email@example.com", null, asList("ext-id-1", "ext-id-2"), "otpKey", "3745838475", null);
    when(mockServiceDao.findByExternalId("ext-id-1")).thenReturn(Optional.of(mock(ServiceEntity.class)));
    when(mockServiceDao.findByExternalId("ext-id-2")).thenReturn(Optional.of(mock(ServiceEntity.class)));
    User user = userCreator.doCreate(request, validRole);
    verify(mockUserDao).persist(expectedUser.capture());
    assertThat(expectedUser.getValue().getEmail(), is("email@example.com"));
    assertThat(user.getEmail(), is("email@example.com"));
    assertThat(user.getSecondFactor(), is(SecondFactorMethod.SMS));
    assertThat(user.getServiceRoles().size(), is(2));
}
Also used : User(uk.gov.pay.adminusers.model.User) CreateUserRequest(uk.gov.pay.adminusers.model.CreateUserRequest) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)5 CreateUserRequest (uk.gov.pay.adminusers.model.CreateUserRequest)5 User (uk.gov.pay.adminusers.model.User)4 WebApplicationException (javax.ws.rs.WebApplicationException)1 Service (uk.gov.pay.adminusers.model.Service)1 ServiceEntity (uk.gov.pay.adminusers.persistence.entity.ServiceEntity)1