use of uk.gov.pay.products.persistence.entity.ProductEntity in project pay-products by alphagov.
the class PaymentCreatorTest method shouldCreateAMotoPaymentWithCardAgentInitiatedMotoSource_whenProductIsAgentInitiatedMoto.
@Test
public void shouldCreateAMotoPaymentWithCardAgentInitiatedMotoSource_whenProductIsAgentInitiatedMoto() {
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";
String userDefinedReference = "user-defined-reference";
Integer gatewayAccountId = 1;
String paymentId = "payment-id";
String paymentExternalId = "random-external-id";
String paymentNextUrl = "http://next.url";
SupportedLanguage language = SupportedLanguage.ENGLISH;
Long priceOverride = 500L;
ProductEntity productEntity = createProductEntity(productId, ProductType.AGENT_INITIATED_MOTO, productPrice, productExternalId, productName, "", productApiToken, gatewayAccountId, true, language);
PaymentRequest expectedPaymentRequest = createPaymentRequest(priceOverride, userDefinedReference, productName, productReturnUrl + "/" + paymentExternalId, language, true, Map.of(), CARD_AGENT_INITIATED_MOTO);
PaymentResponse paymentResponse = createPaymentResponse(paymentId, priceOverride, paymentNextUrl, productReturnUrl);
when(productDao.findByExternalId(productExternalId)).thenReturn(Optional.of(productEntity));
when(randomUuid()).thenReturn(paymentExternalId);
when(productsConfiguration.getProductsUiConfirmUrl()).thenReturn(productReturnUrl);
when(publicApiRestClient.createPayment(argThat(is(productApiToken)), argThat(PaymentRequestMatcher.isSame(expectedPaymentRequest)))).thenReturn(paymentResponse);
Payment payment = paymentCreator.doCreate(productExternalId, priceOverride, userDefinedReference);
assertNotNull(payment);
assertNotNull(payment.getExternalId());
assertThat(payment.getGovukPaymentId(), is(paymentResponse.getPaymentId()));
assertThat(payment.getAmount(), is(500L));
assertThat(payment.getReferenceNumber(), is(userDefinedReference));
PaymentEntity expectedPaymentEntity = createPaymentEntity(paymentId, userDefinedReference, paymentNextUrl, productEntity, SUBMITTED, priceOverride);
verify(paymentDao).merge(argThat(PaymentEntityMatcher.isSame(expectedPaymentEntity)));
}
use of uk.gov.pay.products.persistence.entity.ProductEntity in project pay-products by alphagov.
the class PaymentCreatorTest method createProductEntity.
private ProductEntity createProductEntity(int id, ProductType type, long price, String externalId, String name, String returnUrl, String apiToken, Integer gatewayAccountId, Boolean referenceEnabled, SupportedLanguage language) {
ProductEntity productEntity = createProductEntity(id, price, externalId, name, returnUrl, apiToken, gatewayAccountId, referenceEnabled, language);
productEntity.setType(type);
return productEntity;
}
use of uk.gov.pay.products.persistence.entity.ProductEntity in project pay-products by alphagov.
the class PaymentCreatorTest method shouldThrowPaymentCreationException_whenReferenceEnabledAndNoReferencePresent.
@Test
public void shouldThrowPaymentCreationException_whenReferenceEnabledAndNoReferencePresent() {
int productId = 1;
String productExternalId = "product-external-id";
long productPrice = 100L;
String productName = "name";
String productReturnUrl = "https://return.url";
String productApiToken = "api-token";
SupportedLanguage language = SupportedLanguage.WELSH;
Integer gatewayAccountId = 1;
ProductEntity productEntity = createProductEntity(productId, productPrice, productExternalId, productName, productReturnUrl, productApiToken, gatewayAccountId, true, language);
when(productDao.findByExternalId(productExternalId)).thenReturn(Optional.of(productEntity));
thrown.expect(BadPaymentRequestException.class);
thrown.expectMessage("User defined reference is enabled but missing");
paymentCreator.doCreate(productExternalId, null, null);
}
use of uk.gov.pay.products.persistence.entity.ProductEntity in project pay-products by alphagov.
the class ProductCreatorTest method shouldSuccess_whenProvidedAProductWithMinimumRequiredFields.
@Test
public void shouldSuccess_whenProvidedAProductWithMinimumRequiredFields() {
Product basicProduct = new Product(null, PRODUCT_NAME, null, payApiToken, PRICE, null, gatewayAccountId, ProductType.DEMO, null, null, null, SupportedLanguage.ENGLISH, null);
Product product = productCreator.doCreate(basicProduct);
assertThat(product.getName(), is("Test product name"));
assertThat(product.getPrice(), is(1050L));
assertThat(product.getPayApiToken(), is(payApiToken));
assertThat(product.getGatewayAccountId(), is(gatewayAccountId));
verify(productDao).persist(persistedProductEntity.capture());
ProductEntity productEntity = persistedProductEntity.getValue();
assertThat(productEntity.getName(), is("Test product name"));
assertThat(productEntity.getPrice(), is(1050L));
assertThat(productEntity.getPayApiToken(), is(payApiToken));
assertThat(productEntity.getExternalId(), is(not(emptyOrNullString())));
assertThat(productEntity.getDateCreated(), is(notNullValue()));
assertThat(productEntity.getGatewayAccountId(), is(notNullValue()));
assertThat(productEntity.getGatewayAccountId(), is(gatewayAccountId));
assertThat(productEntity.getType(), is(notNullValue()));
assertThat(productEntity.getType(), is(ProductType.DEMO));
assertThat(productEntity.getLanguage(), is(SupportedLanguage.ENGLISH));
}
use of uk.gov.pay.products.persistence.entity.ProductEntity in project pay-products by alphagov.
the class ProductCreatorTest method doUpdateByGatewayAccountId_referenceEnabled_shouldUpdateProduct.
@Test
public void doUpdateByGatewayAccountId_referenceEnabled_shouldUpdateProduct() {
String updatedName = "updated-name";
String updatedDescription = "updated-description";
Long updatedPrice = 500L;
String updatedReferenceLabel = "updated-reference-label";
String updatedReferenceHint = "updated-reference-hint";
ProductMetadata metadata = new ProductMetadata("key-1", "value-1");
ProductUpdateRequest productUpdateRequest = new ProductUpdateRequest(updatedName, updatedDescription, updatedPrice, true, updatedReferenceLabel, updatedReferenceHint, List.of(metadata));
ProductEntity productEntity = aProductEntity().build();
when(productDao.findByGatewayAccountIdAndExternalId(gatewayAccountId, externalId)).thenReturn(Optional.of(productEntity));
Optional<Product> maybeUpdatedProduct = productCreator.doUpdateByGatewayAccountId(gatewayAccountId, externalId, productUpdateRequest);
assertTrue(maybeUpdatedProduct.isPresent());
Product updatedProduct = maybeUpdatedProduct.get();
assertThat(updatedProduct.getName(), is(updatedName));
assertThat(updatedProduct.getDescription(), is(updatedDescription));
assertThat(updatedProduct.getPrice(), is(updatedPrice));
assertThat(updatedProduct.getReferenceEnabled(), is(productUpdateRequest.getReferenceEnabled()));
assertThat(updatedProduct.getReferenceLabel(), is(updatedReferenceLabel));
assertThat(updatedProduct.getReferenceHint(), is(updatedReferenceHint));
assertThat(updatedProduct.getMetadata(), contains(metadata));
verify(productMetadataDao).deleteForProductExternalId("external-id");
}
Aggregations