use of uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity in project pay-connector by alphagov.
the class GatewayAccountCredentialsServiceTest method shouldReturnGatewayAccountCredentialForMatchedCredentialExternalId.
@Test
void shouldReturnGatewayAccountCredentialForMatchedCredentialExternalId() {
GatewayAccountCredentialsEntity aGatewayAccountCredentialsEntityOne = GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity().build();
GatewayAccountCredentialsEntity aGatewayAccountCredentialsEntityTwo = GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity().build();
GatewayAccountEntity gatewayAccountEntity = aGatewayAccountEntity().withGatewayAccountCredentials(List.of(aGatewayAccountCredentialsEntityOne, aGatewayAccountCredentialsEntityTwo)).build();
Charge charge = Charge.from(ChargeEntityFixture.aValidChargeEntity().withGatewayAccountCredentialsEntity(aGatewayAccountCredentialsEntityOne).build());
String expectedCredentialsExternalId = aGatewayAccountCredentialsEntityOne.getExternalId();
Optional<GatewayAccountCredentialsEntity> gatewayAccountCredentialsEntity = gatewayAccountCredentialsService.findCredentialFromCharge(charge, gatewayAccountEntity);
assertThat(gatewayAccountCredentialsEntity.isPresent(), is(true));
assertThat(gatewayAccountCredentialsEntity.get().getExternalId(), is(expectedCredentialsExternalId));
}
use of uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity in project pay-connector by alphagov.
the class GatewayAccountCredentialsServiceTest method shouldUpdateStateToActiveIfNotActive.
@Test
void shouldUpdateStateToActiveIfNotActive() {
String stripeCredentialId = "credentialId";
GatewayAccountEntity gatewayAccountEntity = aGatewayAccountEntity().build();
GatewayAccountCredentialsEntity gatewayAccountCredentialsEntity = GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity().withPaymentProvider(STRIPE.getName()).withState(CREATED).withCredentials(Map.of(StripeCredentials.STRIPE_ACCOUNT_ID_KEY, stripeCredentialId)).withGatewayAccountEntity(gatewayAccountEntity).build();
gatewayAccountEntity.setGatewayAccountCredentials(List.of(gatewayAccountCredentialsEntity));
when(mockGatewayAccountCredentialsDao.findByCredentialsKeyValue(StripeCredentials.STRIPE_ACCOUNT_ID_KEY, stripeCredentialId)).thenReturn(Optional.of(gatewayAccountCredentialsEntity));
gatewayAccountCredentialsService.activateCredentialIfNotYetActive(stripeCredentialId);
verify(mockGatewayAccountCredentialsDao, times(1)).merge(any(GatewayAccountCredentialsEntity.class));
}
use of uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity in project pay-connector by alphagov.
the class GatewayAccountCredentialsServiceTest method shouldUpdateStateToEnteredIfActiveCredentialAlreadyExists.
@Test
void shouldUpdateStateToEnteredIfActiveCredentialAlreadyExists() {
String stripeCredentialId = "credentialId";
GatewayAccountEntity gatewayAccountEntity = aGatewayAccountEntity().build();
GatewayAccountCredentialsEntity updatableEntity = GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity().withPaymentProvider(STRIPE.getName()).withState(CREATED).withCredentials(Map.of(StripeCredentials.STRIPE_ACCOUNT_ID_KEY, stripeCredentialId)).withGatewayAccountEntity(gatewayAccountEntity).build();
GatewayAccountCredentialsEntity existingEntity = GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity().withPaymentProvider(STRIPE.getName()).withState(ACTIVE).withCredentials(Map.of(StripeCredentials.STRIPE_ACCOUNT_ID_KEY, stripeCredentialId)).withGatewayAccountEntity(gatewayAccountEntity).build();
gatewayAccountEntity.setGatewayAccountCredentials(List.of(updatableEntity, existingEntity));
when(mockGatewayAccountCredentialsDao.findByCredentialsKeyValue(StripeCredentials.STRIPE_ACCOUNT_ID_KEY, stripeCredentialId)).thenReturn(Optional.of(updatableEntity));
gatewayAccountCredentialsService.activateCredentialIfNotYetActive(stripeCredentialId);
assertThat(updatableEntity.getState(), is(ENTERED));
verify(mockGatewayAccountCredentialsDao, times(1)).merge(any(GatewayAccountCredentialsEntity.class));
}
use of uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity in project pay-connector by alphagov.
the class GatewayAccountCredentialsServiceTest method shouldReturnFirstGatewayAccountCredentialIfNoneCreatedBeforeChargeWhenSearchingByPaymentProvider.
@Test
void shouldReturnFirstGatewayAccountCredentialIfNoneCreatedBeforeChargeWhenSearchingByPaymentProvider() {
Charge charge = Charge.from(ChargeEntityFixture.aValidChargeEntity().withCreatedDate(Instant.parse("2021-08-16T10:00:00Z")).withPaymentProvider(WORLDPAY.getName()).build());
GatewayAccountCredentialsEntity worldpayGatewayAccountCredentialsEntityOne = GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity().withPaymentProvider(WORLDPAY.getName()).withCreatedDate(Instant.parse("2021-08-17T13:00:00Z")).build();
GatewayAccountCredentialsEntity smartpayGatewayAccountCredentialsEntityOne = GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity().withPaymentProvider(WORLDPAY.getName()).withCreatedDate(Instant.parse("2021-08-18T15:00:00Z")).build();
GatewayAccountEntity gatewayAccountEntity = aGatewayAccountEntity().withGatewayAccountCredentials(List.of(worldpayGatewayAccountCredentialsEntityOne, smartpayGatewayAccountCredentialsEntityOne)).build();
Optional<GatewayAccountCredentialsEntity> gatewayAccountCredentialsEntity = gatewayAccountCredentialsService.findCredentialFromCharge(charge, gatewayAccountEntity);
assertThat(gatewayAccountCredentialsEntity.isPresent(), is(true));
assertThat(gatewayAccountCredentialsEntity.get().getPaymentProvider(), is("worldpay"));
assertThat(gatewayAccountCredentialsEntity.get().getCreatedDate(), is(Instant.parse("2021-08-17T13:00:00Z")));
}
use of uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity in project pay-connector by alphagov.
the class GatewayAccountCredentialsServiceTest method shouldReturnGatewayAccountCredentialCreatedBeforeChargeIfMultipleCredentialsExistWhenSearchingByPaymentProvider.
@Test
void shouldReturnGatewayAccountCredentialCreatedBeforeChargeIfMultipleCredentialsExistWhenSearchingByPaymentProvider() {
Charge charge = Charge.from(ChargeEntityFixture.aValidChargeEntity().withCreatedDate(Instant.parse("2021-08-16T10:00:00Z")).withPaymentProvider(WORLDPAY.getName()).build());
GatewayAccountCredentialsEntity worldpayGatewayAccountCredentialsEntityOne = GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity().withPaymentProvider(WORLDPAY.getName()).withCreatedDate(Instant.parse("2021-08-15T13:00:00Z")).build();
GatewayAccountCredentialsEntity smartpayGatewayAccountCredentialsEntityOne = GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity().withPaymentProvider(WORLDPAY.getName()).withCreatedDate(Instant.parse("2021-08-17T15:00:00Z")).build();
GatewayAccountEntity gatewayAccountEntity = aGatewayAccountEntity().withGatewayAccountCredentials(List.of(worldpayGatewayAccountCredentialsEntityOne, smartpayGatewayAccountCredentialsEntityOne)).build();
Optional<GatewayAccountCredentialsEntity> gatewayAccountCredentialsEntity = gatewayAccountCredentialsService.findCredentialFromCharge(charge, gatewayAccountEntity);
assertThat(gatewayAccountCredentialsEntity.isPresent(), is(true));
assertThat(gatewayAccountCredentialsEntity.get().getPaymentProvider(), is("worldpay"));
assertThat(gatewayAccountCredentialsEntity.get().getCreatedDate(), is(Instant.parse("2021-08-15T13:00:00Z")));
}
Aggregations