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