use of uk.gov.pay.connector.gateway.CaptureResponse.fromBaseCaptureResponse in project pay-connector by alphagov.
the class CardCaptureServiceTest method verifyChargeIsCapturedImmediatelyFromPaymentProvider.
public void verifyChargeIsCapturedImmediatelyFromPaymentProvider(ChargeEntity chargeSpy) {
mockChargeDaoOperations(chargeSpy);
when(mockedProviders.byName(chargeSpy.getPaymentGatewayName())).thenReturn(mockedPaymentProvider);
when(mockedPaymentProvider.capture(any())).thenReturn(CaptureResponse.fromBaseCaptureResponse(BaseCaptureResponse.fromTransactionId(randomUUID().toString(), SANDBOX), COMPLETE));
CaptureResponse response = cardCaptureService.doCapture(chargeSpy.getExternalId());
assertThat(response.isSuccessful(), is(true));
InOrder inOrder = Mockito.inOrder(chargeSpy);
inOrder.verify(chargeSpy).setStatus(CAPTURE_READY);
inOrder.verify(chargeSpy).setStatus(CAPTURE_SUBMITTED);
inOrder.verify(chargeSpy).setStatus(CAPTURED);
ArgumentCaptor<ChargeEntity> chargeEntityCaptor = ArgumentCaptor.forClass(ChargeEntity.class);
// charge progresses from CAPTURE_SUBMITTED to CAPTURED, so two calls
// first invocation will add a captured date
verify(mockedChargeEventDao, times(2)).persistChargeEventOf(chargeEntityCaptor.capture(), isNull());
// second invocation will NOT add a captured date
assertThat(chargeEntityCaptor.getValue().getStatus(), is(CAPTURED.getValue()));
// only the CAPTURED has a bookingDate, so there's only one value captured
ArgumentCaptor<CaptureGatewayRequest> request = ArgumentCaptor.forClass(CaptureGatewayRequest.class);
verify(mockedPaymentProvider, times(1)).capture(request.capture());
assertThat(request.getValue().getTransactionId(), is(chargeSpy.getGatewayTransactionId()));
}
Aggregations