use of uk.gov.pay.adminusers.model.InviteCompleteRequest in project pay-adminusers by alphagov.
the class ServiceInviteCompleterTest method shouldCreateServiceAndUser_withGatewayAccounts_whenPassedValidServiceInviteCode.
@Test
public void shouldCreateServiceAndUser_withGatewayAccounts_whenPassedValidServiceInviteCode() {
ServiceEntity service = new ServiceEntity();
service.setId(serviceId);
InviteEntity anInvite = createInvite();
anInvite.setType(InviteType.SERVICE);
when(mockUserDao.findByEmail(email)).thenReturn(Optional.empty());
when(mockInviteDao.findByCode(inviteCode)).thenReturn(Optional.of(anInvite));
InviteCompleteRequest data = new InviteCompleteRequest();
data.setGatewayAccountIds(asList("1", "2"));
InviteCompleteResponse inviteResponse = serviceInviteCompleter.withData(data).complete(anInvite.getCode()).get();
verify(mockServiceDao).persist(expectedService.capture());
verify(mockUserDao).merge(expectedInvitedUser.capture());
verify(mockInviteDao).merge(expectedInvite.capture());
ServiceEntity serviceEntity = expectedService.getValue();
assertThat(serviceEntity.getGatewayAccountIds().stream().map(GatewayAccountIdEntity::getGatewayAccountId).collect(toUnmodifiableList()), hasItems("2", "1"));
assertThat(serviceEntity.getServiceNames().get(SupportedLanguage.ENGLISH).getName(), is(Service.DEFAULT_NAME_VALUE));
assertThat(serviceEntity.isRedirectToServiceImmediatelyOnTerminalState(), is(false));
assertThat(serviceEntity.isCollectBillingAddress(), is(true));
assertThat(serviceEntity.getDefaultBillingAddressCountry(), is("GB"));
assertThat(inviteResponse.getInvite().isDisabled(), is(true));
assertThat(inviteResponse.getInvite().getLinks().size(), is(1));
assertThat(inviteResponse.getInvite().getLinks().get(0).getRel(), is(Link.Rel.USER));
assertThat(inviteResponse.getInvite().getLinks().get(0).getHref(), matchesPattern("^" + baseUrl + "/v1/api/users/[0-9a-z]{32}$"));
}
use of uk.gov.pay.adminusers.model.InviteCompleteRequest in project pay-adminusers by alphagov.
the class ServiceInviteCompleterTest method shouldCreateServiceAndUser_withoutGatewayAccounts_whenPassedValidServiceInviteCode.
@Test
public void shouldCreateServiceAndUser_withoutGatewayAccounts_whenPassedValidServiceInviteCode() {
ServiceEntity service = new ServiceEntity();
service.addOrUpdateServiceName(ServiceNameEntity.from(SupportedLanguage.ENGLISH, Service.DEFAULT_NAME_VALUE));
service.setId(serviceId);
InviteEntity anInvite = createInvite();
anInvite.setType(InviteType.SERVICE);
when(mockUserDao.findByEmail(email)).thenReturn(Optional.empty());
when(mockInviteDao.findByCode(inviteCode)).thenReturn(Optional.of(anInvite));
InviteCompleteResponse inviteResponse = serviceInviteCompleter.withData(new InviteCompleteRequest()).complete(anInvite.getCode()).get();
verify(mockServiceDao).persist(expectedService.capture());
verify(mockUserDao).merge(expectedInvitedUser.capture());
verify(mockInviteDao).merge(expectedInvite.capture());
assertThat(expectedService.getValue().getGatewayAccountIds().isEmpty(), is(true));
ServiceEntity serviceEntity = expectedService.getValue();
assertThat(serviceEntity.getGatewayAccountIds().isEmpty(), is(true));
assertThat(serviceEntity.getServiceNames().get(SupportedLanguage.ENGLISH).getName(), is(Service.DEFAULT_NAME_VALUE));
assertThat(serviceEntity.isRedirectToServiceImmediatelyOnTerminalState(), is(false));
assertThat(serviceEntity.isCollectBillingAddress(), is(true));
assertThat(serviceEntity.getDefaultBillingAddressCountry(), is("GB"));
assertThat(inviteResponse.getInvite().isDisabled(), is(true));
assertThat(inviteResponse.getInvite().getLinks().size(), is(1));
assertThat(inviteResponse.getInvite().getLinks().get(0).getRel(), is(Link.Rel.USER));
assertThat(inviteResponse.getInvite().getLinks().get(0).getHref(), matchesPattern("^" + baseUrl + "/v1/api/users/[0-9a-z]{32}$"));
}
use of uk.gov.pay.adminusers.model.InviteCompleteRequest in project pay-adminusers by alphagov.
the class InviteResource method inviteCompleteRequestFrom.
private InviteCompleteRequest inviteCompleteRequestFrom(JsonNode payload) {
InviteCompleteRequest inviteCompleteRequest = new InviteCompleteRequest();
if (payload != null && payload.get(InviteCompleteRequest.FIELD_GATEWAY_ACCOUNT_IDS) != null) {
List<String> gatewayAccountIds = new ArrayList<>();
payload.get(InviteCompleteRequest.FIELD_GATEWAY_ACCOUNT_IDS).elements().forEachRemaining((node) -> gatewayAccountIds.add(node.textValue()));
inviteCompleteRequest.setGatewayAccountIds(gatewayAccountIds);
}
return inviteCompleteRequest;
}
Aggregations