Search in sources :

Example 1 with GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity

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));
}
Also used : GatewayAccountEntityFixture.aGatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntityFixture.aGatewayAccountEntity) GatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity) Charge(uk.gov.pay.connector.charge.model.domain.Charge) GatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntity) GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity

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));
}
Also used : GatewayAccountEntityFixture.aGatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntityFixture.aGatewayAccountEntity) GatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity) GatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntity) GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity

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));
}
Also used : GatewayAccountEntityFixture.aGatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntityFixture.aGatewayAccountEntity) GatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity) GatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntity) GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity

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")));
}
Also used : Charge(uk.gov.pay.connector.charge.model.domain.Charge) GatewayAccountEntityFixture.aGatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntityFixture.aGatewayAccountEntity) GatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity) GatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntity) GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity

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")));
}
Also used : Charge(uk.gov.pay.connector.charge.model.domain.Charge) GatewayAccountEntityFixture.aGatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntityFixture.aGatewayAccountEntity) GatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity) GatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntity) GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity(uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 GatewayAccountCredentialsEntity (uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntity)10 GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity (uk.gov.pay.connector.gatewayaccountcredentials.model.GatewayAccountCredentialsEntityFixture.aGatewayAccountCredentialsEntity)10 Test (org.junit.jupiter.api.Test)9 GatewayAccountEntity (uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity)9 GatewayAccountEntityFixture.aGatewayAccountEntity (uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntityFixture.aGatewayAccountEntity)9 Charge (uk.gov.pay.connector.charge.model.domain.Charge)6 ValueSource (org.junit.jupiter.params.provider.ValueSource)1