Search in sources :

Example 1 with InviteEntity

use of uk.gov.pay.adminusers.persistence.entity.InviteEntity in project pay-adminusers by alphagov.

the class UserInviteCompleterTest method shouldThrowEmailExistsException_whenPassedInviteCodeWhichIsExpired.

@Test
public void shouldThrowEmailExistsException_whenPassedInviteCodeWhichIsExpired() {
    InviteEntity anInvite = createInvite();
    anInvite.setType(InviteType.USER);
    anInvite.setExpiryDate(ZonedDateTime.now().minusDays(1));
    when(mockInviteDao.findByCode(inviteCode)).thenReturn(Optional.of(anInvite));
    WebApplicationException webApplicationException = assertThrows(WebApplicationException.class, () -> userInviteCompleter.complete(inviteCode));
    assertThat(webApplicationException.getMessage(), is("HTTP 410 Gone"));
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) InviteEntity(uk.gov.pay.adminusers.persistence.entity.InviteEntity) Test(org.junit.jupiter.api.Test)

Example 2 with InviteEntity

use of uk.gov.pay.adminusers.persistence.entity.InviteEntity in project pay-adminusers by alphagov.

the class UserInviteCompleterTest method shouldThrowInternalError_whenUserWithSpecifiedEmailNotExists.

@Test
public void shouldThrowInternalError_whenUserWithSpecifiedEmailNotExists() {
    InviteEntity anInvite = createInvite();
    anInvite.setType(InviteType.USER);
    when(mockInviteDao.findByCode(inviteCode)).thenReturn(Optional.of(anInvite));
    when(mockUserDao.findByEmail(email)).thenReturn(Optional.empty());
    WebApplicationException webApplicationException = assertThrows(WebApplicationException.class, () -> userInviteCompleter.complete(inviteCode));
    assertThat(webApplicationException.getMessage(), is("HTTP 500 Internal Server Error"));
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) InviteEntity(uk.gov.pay.adminusers.persistence.entity.InviteEntity) Test(org.junit.jupiter.api.Test)

Example 3 with InviteEntity

use of uk.gov.pay.adminusers.persistence.entity.InviteEntity in project pay-adminusers by alphagov.

the class UserInviteCompleterTest method anInvite.

private InviteEntity anInvite(String email, String code, String otpKey, UserEntity userEntity, ServiceEntity serviceEntity, RoleEntity roleEntity) {
    InviteEntity anInvite = new InviteEntity(email, code, otpKey, roleEntity);
    anInvite.setSender(userEntity);
    anInvite.setService(serviceEntity);
    return anInvite;
}
Also used : InviteEntity(uk.gov.pay.adminusers.persistence.entity.InviteEntity)

Example 4 with InviteEntity

use of uk.gov.pay.adminusers.persistence.entity.InviteEntity in project pay-adminusers by alphagov.

the class UserInviteCompleterTest method shouldError_whenSubscribingAServiceToAnExistingUser_ifInviteIsNotUserType.

@Test
public void shouldError_whenSubscribingAServiceToAnExistingUser_ifInviteIsNotUserType() {
    ServiceEntity service = new ServiceEntity();
    service.setId(serviceId);
    service.setExternalId(serviceExternalId);
    InviteEntity anInvite = createInvite();
    anInvite.setType(InviteType.SERVICE);
    anInvite.setService(service);
    UserEntity user = UserEntity.from(aUser(anInvite.getEmail()));
    when(mockInviteDao.findByCode(inviteCode)).thenReturn(Optional.of(anInvite));
    when(mockUserDao.findByEmail(email)).thenReturn(Optional.of(user));
    WebApplicationException webApplicationException = assertThrows(WebApplicationException.class, () -> userInviteCompleter.complete(inviteCode));
    assertThat(webApplicationException.getMessage(), is("HTTP 500 Internal Server Error"));
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) InviteEntity(uk.gov.pay.adminusers.persistence.entity.InviteEntity) ServiceEntity(uk.gov.pay.adminusers.persistence.entity.ServiceEntity) UserEntity(uk.gov.pay.adminusers.persistence.entity.UserEntity) Test(org.junit.jupiter.api.Test)

Example 5 with InviteEntity

use of uk.gov.pay.adminusers.persistence.entity.InviteEntity in project pay-adminusers by alphagov.

the class UserInviteCompleterTest method shouldThrowEmailExistsException_whenPassedInviteCodeWhichIsDisabled.

@Test
public void shouldThrowEmailExistsException_whenPassedInviteCodeWhichIsDisabled() {
    InviteEntity anInvite = createInvite();
    anInvite.setType(InviteType.USER);
    anInvite.setDisabled(true);
    when(mockInviteDao.findByCode(inviteCode)).thenReturn(Optional.of(anInvite));
    WebApplicationException webApplicationException = assertThrows(WebApplicationException.class, () -> userInviteCompleter.complete(inviteCode));
    assertThat(webApplicationException.getMessage(), is("HTTP 410 Gone"));
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) InviteEntity(uk.gov.pay.adminusers.persistence.entity.InviteEntity) Test(org.junit.jupiter.api.Test)

Aggregations

InviteEntity (uk.gov.pay.adminusers.persistence.entity.InviteEntity)61 Test (org.junit.jupiter.api.Test)50 WebApplicationException (javax.ws.rs.WebApplicationException)18 ServiceEntity (uk.gov.pay.adminusers.persistence.entity.ServiceEntity)18 UserEntity (uk.gov.pay.adminusers.persistence.entity.UserEntity)14 Invite (uk.gov.pay.adminusers.model.Invite)13 RoleEntity (uk.gov.pay.adminusers.persistence.entity.RoleEntity)8 InviteUserRequest (uk.gov.pay.adminusers.model.InviteUserRequest)7 InviteValidateOtpRequest (uk.gov.pay.adminusers.model.InviteValidateOtpRequest)6 Transactional (com.google.inject.persist.Transactional)4 Pair (org.apache.commons.lang3.tuple.Pair)4 ServiceRoleEntity (uk.gov.pay.adminusers.persistence.entity.ServiceRoleEntity)4 Optional (java.util.Optional)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 InviteCompleteResponse (uk.gov.pay.adminusers.model.InviteCompleteResponse)3 InviteServiceRequest (uk.gov.pay.adminusers.model.InviteServiceRequest)3 InviteDao (uk.gov.pay.adminusers.persistence.dao.InviteDao)3 UserDao (uk.gov.pay.adminusers.persistence.dao.UserDao)3 String.format (java.lang.String.format)2