Search in sources :

Example 1 with GatewayAccountIdEntity

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

the class ServiceDaoIT method shouldMergePSPTestAccountStage.

@Test
void shouldMergePSPTestAccountStage() {
    GatewayAccountIdEntity gatewayAccountIdEntity = new GatewayAccountIdEntity();
    String gatewayAccountId = randomUuid();
    gatewayAccountIdEntity.setGatewayAccountId(gatewayAccountId);
    ServiceEntity insertedServiceEntity = ServiceEntityBuilder.aServiceEntity().withGatewayAccounts(Collections.singletonList(gatewayAccountIdEntity)).build();
    gatewayAccountIdEntity.setService(insertedServiceEntity);
    databaseHelper.insertServiceEntity(insertedServiceEntity);
    Optional<ServiceEntity> optionalService = serviceDao.findByGatewayAccountId(insertedServiceEntity.getGatewayAccountId().getGatewayAccountId());
    assertThat(optionalService.isPresent(), is(true));
    assertThat(optionalService.get().getCurrentPspTestAccountStage(), is(PspTestAccountStage.NOT_STARTED));
    optionalService.get().setCurrentPspTestAccountStage(PspTestAccountStage.REQUEST_SUBMITTED);
    serviceDao.merge(optionalService.get());
    optionalService = serviceDao.findByGatewayAccountId(insertedServiceEntity.getGatewayAccountId().getGatewayAccountId());
    assertThat(optionalService.isPresent(), is(true));
    assertThat(optionalService.get().getCurrentPspTestAccountStage(), is(PspTestAccountStage.REQUEST_SUBMITTED));
}
Also used : GatewayAccountIdEntity(uk.gov.pay.adminusers.persistence.entity.GatewayAccountIdEntity) ServiceEntity(uk.gov.pay.adminusers.persistence.entity.ServiceEntity) Test(org.junit.jupiter.api.Test)

Example 2 with GatewayAccountIdEntity

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

the class ServiceDaoIT method shouldFindByGatewayAccountId.

@Test
void shouldFindByGatewayAccountId() {
    GatewayAccountIdEntity gatewayAccountIdEntity = new GatewayAccountIdEntity();
    String gatewayAccountId = randomUuid();
    gatewayAccountIdEntity.setGatewayAccountId(gatewayAccountId);
    ServiceEntity insertedServiceEntity = ServiceEntityBuilder.aServiceEntity().withGatewayAccounts(Collections.singletonList(gatewayAccountIdEntity)).build();
    gatewayAccountIdEntity.setService(insertedServiceEntity);
    databaseHelper.insertServiceEntity(insertedServiceEntity);
    Optional<ServiceEntity> optionalService = serviceDao.findByGatewayAccountId(insertedServiceEntity.getGatewayAccountId().getGatewayAccountId());
    assertThat(optionalService.isPresent(), is(true));
    ServiceEntity foundServiceEntity = optionalService.get();
    assertServiceEntity(insertedServiceEntity, foundServiceEntity);
}
Also used : GatewayAccountIdEntity(uk.gov.pay.adminusers.persistence.entity.GatewayAccountIdEntity) ServiceEntity(uk.gov.pay.adminusers.persistence.entity.ServiceEntity) Test(org.junit.jupiter.api.Test)

Example 3 with GatewayAccountIdEntity

use of uk.gov.pay.adminusers.persistence.entity.GatewayAccountIdEntity 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 4 with GatewayAccountIdEntity

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

the class ServiceCreatorTest method shouldSuccess_whenProvidedWith_multipleValidNames_andNoGatewayAccountIds.

@Test
public void shouldSuccess_whenProvidedWith_multipleValidNames_andNoGatewayAccountIds() {
    Map<SupportedLanguage, String> serviceNames = new HashMap<>();
    serviceNames.put(SupportedLanguage.ENGLISH, EN_SERVICE_NAME);
    serviceNames.put(SupportedLanguage.WELSH, CY_SERVICE_NAME);
    Service service = serviceCreator.doCreate(Collections.emptyList(), serviceNames);
    verify(mockedServiceDao, never()).checkIfGatewayAccountsUsed(anyList());
    verify(mockedServiceDao, times(1)).persist(persistedServiceEntity.capture());
    assertThat(service.getName(), is(EN_SERVICE_NAME));
    List<GatewayAccountIdEntity> persistedGatewayIds = persistedServiceEntity.getValue().getGatewayAccountIds();
    assertThat(persistedGatewayIds.size(), is(0));
    assertEnServiceNameMap(service, EN_SERVICE_NAME);
    assertThat(service.getServiceNames(), hasKey(SupportedLanguage.WELSH.toString()));
    assertThat(service.getServiceNames(), hasValue(CY_SERVICE_NAME));
    assertSelfLink(service);
}
Also used : GatewayAccountIdEntity(uk.gov.pay.adminusers.persistence.entity.GatewayAccountIdEntity) SupportedLanguage(uk.gov.service.payments.commons.model.SupportedLanguage) HashMap(java.util.HashMap) Service(uk.gov.pay.adminusers.model.Service) Test(org.junit.jupiter.api.Test)

Example 5 with GatewayAccountIdEntity

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

the class ServiceCreatorTest method shouldSuccess_whenProvidedWith_onlyAValidName.

@Test
public void shouldSuccess_whenProvidedWith_onlyAValidName() {
    Service service = serviceCreator.doCreate(Collections.emptyList(), Map.of(SupportedLanguage.ENGLISH, EN_SERVICE_NAME));
    verify(mockedServiceDao, never()).checkIfGatewayAccountsUsed(anyList());
    verify(mockedServiceDao, times(1)).persist(persistedServiceEntity.capture());
    assertThat(service.getName(), is(EN_SERVICE_NAME));
    List<GatewayAccountIdEntity> persistedGatewayIds = persistedServiceEntity.getValue().getGatewayAccountIds();
    assertThat(persistedGatewayIds.size(), is(0));
    assertEnServiceNameMap(service, EN_SERVICE_NAME);
    assertSelfLink(service);
}
Also used : GatewayAccountIdEntity(uk.gov.pay.adminusers.persistence.entity.GatewayAccountIdEntity) Service(uk.gov.pay.adminusers.model.Service) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)9 GatewayAccountIdEntity (uk.gov.pay.adminusers.persistence.entity.GatewayAccountIdEntity)9 ServiceEntity (uk.gov.pay.adminusers.persistence.entity.ServiceEntity)6 Service (uk.gov.pay.adminusers.model.Service)3 JsonPath (io.restassured.path.json.JsonPath)2 Response (javax.ws.rs.core.Response)2 HashMap (java.util.HashMap)1 InviteCompleteRequest (uk.gov.pay.adminusers.model.InviteCompleteRequest)1 InviteCompleteResponse (uk.gov.pay.adminusers.model.InviteCompleteResponse)1 InviteEntity (uk.gov.pay.adminusers.persistence.entity.InviteEntity)1 SupportedLanguage (uk.gov.service.payments.commons.model.SupportedLanguage)1