use of uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity in project pay-connector by alphagov.
the class ChargeEntityTest method shouldAllowAValidStatusTransition.
@Test
public void shouldAllowAValidStatusTransition() {
ChargeEntity chargeCreated = ChargeEntityFixture.aValidChargeEntity().withStatus(CREATED).build();
chargeCreated.setStatus(ENTERING_CARD_DETAILS);
assertThat(chargeCreated.getStatus(), is(ENTERING_CARD_DETAILS.toString()));
}
use of uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity in project pay-connector by alphagov.
the class ChargeEntityTest method shouldReturnAmountMinusFeeForSuccessfulPayment.
@Test
public void shouldReturnAmountMinusFeeForSuccessfulPayment() {
ChargeEntity chargeCreated = ChargeEntityFixture.aValidChargeEntity().withAmount(1000L).withFee(Fee.of(FeeType.TRANSACTION, 100L)).withFee(Fee.of(FeeType.RADAR, 10L)).withFee(Fee.of(FeeType.THREE_D_S, 20L)).withStatus(CAPTURED).build();
Optional<Long> netAmount = chargeCreated.getNetAmount();
assertThat(netAmount.isPresent(), is(true));
assertThat(netAmount.get(), is(870L));
}
use of uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity in project pay-connector by alphagov.
the class ChargeEntityTest method shouldReturnEmptyOptionalWhenThereAreNoFees.
@Test
public void shouldReturnEmptyOptionalWhenThereAreNoFees() {
ChargeEntity chargeCreated = ChargeEntityFixture.aValidChargeEntity().withAmount(1000L).withStatus(CAPTURED).build();
Optional<Long> netAmount = chargeCreated.getNetAmount();
assertThat(netAmount.isPresent(), is(false));
}
use of uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity in project pay-connector by alphagov.
the class ChargeEntityTest method shouldRejectAnInvalidStatusTransition.
@Test(expected = InvalidStateTransitionException.class)
public void shouldRejectAnInvalidStatusTransition() {
ChargeEntity chargeCreated = ChargeEntityFixture.aValidChargeEntity().withStatus(CREATED).build();
chargeCreated.setStatus(CAPTURED);
}
use of uk.gov.pay.connector.charge.model.domain.ChargeEntityFixture.aValidChargeEntity in project pay-connector by alphagov.
the class ChargeServiceTest method shouldUpdateStateOrProvinceForChargeWhenCountryIsUs.
@Test
public void shouldUpdateStateOrProvinceForChargeWhenCountryIsUs() {
ChargeEntity chargeSpy = spy(ChargeEntityFixture.aValidChargeEntity().build());
ChargeEventEntity chargeEvent = mock(ChargeEventEntity.class);
AuthCardDetails authCardDetails = new AuthCardDetails();
Address address = new Address();
address.setCountry("US");
address.setPostcode("20500");
authCardDetails.setAddress(address);
authCardDetails.setCardNo("1234567890");
when(chargeEvent.getStatus()).thenReturn(ENTERING_CARD_DETAILS);
when(chargeEvent.getUpdated()).thenReturn(now());
when(mockedChargeEventDao.persistChargeEventOf(chargeSpy, null)).thenReturn(chargeEvent);
when(mockedChargeDao.findByExternalId(chargeSpy.getExternalId())).thenReturn(Optional.of(chargeSpy));
when(mockNorthAmericanRegionMapper.getNorthAmericanRegionForCountry(any(Address.class))).thenAnswer((Answer<Optional<? extends NorthAmericaRegion>>) invocationOnMock -> Optional.of(UsState.WASHINGTON_DC));
when(chargeSpy.getEvents()).thenReturn(List.of(chargeEvent));
service.updateChargeAndEmitEventPostAuthorisation(chargeSpy.getExternalId(), ENTERING_CARD_DETAILS, authCardDetails, null, null, null, null, null);
assertThat(chargeSpy.getCardDetails().getBillingAddress().get().getStateOrProvince(), is("DC"));
}
Aggregations