Search in sources :

Example 1 with InviteCompleteRequest

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}$"));
}
Also used : GatewayAccountIdEntity(uk.gov.pay.adminusers.persistence.entity.GatewayAccountIdEntity) InviteEntity(uk.gov.pay.adminusers.persistence.entity.InviteEntity) InviteCompleteRequest(uk.gov.pay.adminusers.model.InviteCompleteRequest) ServiceEntity(uk.gov.pay.adminusers.persistence.entity.ServiceEntity) InviteCompleteResponse(uk.gov.pay.adminusers.model.InviteCompleteResponse) Test(org.junit.jupiter.api.Test)

Example 2 with InviteCompleteRequest

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}$"));
}
Also used : InviteEntity(uk.gov.pay.adminusers.persistence.entity.InviteEntity) InviteCompleteRequest(uk.gov.pay.adminusers.model.InviteCompleteRequest) ServiceEntity(uk.gov.pay.adminusers.persistence.entity.ServiceEntity) InviteCompleteResponse(uk.gov.pay.adminusers.model.InviteCompleteResponse) Test(org.junit.jupiter.api.Test)

Example 3 with InviteCompleteRequest

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;
}
Also used : InviteCompleteRequest(uk.gov.pay.adminusers.model.InviteCompleteRequest) ArrayList(java.util.ArrayList)

Aggregations

InviteCompleteRequest (uk.gov.pay.adminusers.model.InviteCompleteRequest)3 Test (org.junit.jupiter.api.Test)2 InviteCompleteResponse (uk.gov.pay.adminusers.model.InviteCompleteResponse)2 InviteEntity (uk.gov.pay.adminusers.persistence.entity.InviteEntity)2 ServiceEntity (uk.gov.pay.adminusers.persistence.entity.ServiceEntity)2 ArrayList (java.util.ArrayList)1 GatewayAccountIdEntity (uk.gov.pay.adminusers.persistence.entity.GatewayAccountIdEntity)1