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));
}
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"));
}
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"));
}
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));
}
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));
}
Aggregations