use of uk.gov.pay.products.exception.PaymentCreationException in project pay-products by alphagov.
the class PaymentCreatorTest method shouldCreateAnErrorPayment_whenPublicApiCallFails.
@Test
public void shouldCreateAnErrorPayment_whenPublicApiCallFails() {
PowerMockito.mockStatic(RandomIdGenerator.class);
int productId = 1;
String productExternalId = "product-external-id";
long productPrice = 100L;
String productName = "name";
String productReturnUrl = "https://return.url";
String productApiToken = "api-token";
Integer gatewayAccountId = 1;
String paymentExternalId = "random-external-id";
String referenceNumber = createRandomReferenceNumber();
String productsUIConfirmUri = "https://products-ui/payment-complete";
String paymentReturnUrl = format("%s/%s", productsUIConfirmUri, paymentExternalId);
SupportedLanguage language = SupportedLanguage.WELSH;
ProductEntity productEntity = createProductEntity(productId, productPrice, productExternalId, productName, productReturnUrl, productApiToken, gatewayAccountId, false, language);
PaymentRequest expectedPaymentRequest = createPaymentRequest(productPrice, referenceNumber, productName, paymentReturnUrl, language, false, Map.of(), CARD_PAYMENT_LINK);
when(productDao.findByExternalId(productExternalId)).thenReturn(Optional.of(productEntity));
when(randomUuid()).thenReturn(paymentExternalId);
when(randomUserFriendlyReference()).thenReturn(referenceNumber);
when(productsConfiguration.getProductsUiConfirmUrl()).thenReturn(productsUIConfirmUri);
when(publicApiRestClient.createPayment(argThat(is(productApiToken)), argThat(PaymentRequestMatcher.isSame(expectedPaymentRequest)))).thenThrow(PublicApiResponseErrorException.class);
try {
paymentCreator.doCreate(productExternalId, null, null);
fail("Expected an PaymentCreationException to be thrown");
} catch (PaymentCreationException e) {
assertThat(e.getProductExternalId(), is(productExternalId));
PaymentEntity expectedPaymentEntity = createPaymentEntity(null, null, productEntity, ERROR, null);
verify(paymentDao).merge(argThat(PaymentEntityMatcher.isSame(expectedPaymentEntity)));
}
}
Aggregations