use of uk.gov.pay.products.model.Product in project pay-products by alphagov.
the class ProductApiTokenManagerTest method shouldReplaceApiTokenForAProductWhichExists.
@Test
public void shouldReplaceApiTokenForAProductWhichExists() {
Product modifiedDemoPayment = ProductEntityFixture.aProductEntity().withApiToken(NEW_API_TOKEN_FOR_DEMO_PAYMENT).build().toProduct();
ProductFinder productFinder = mock(ProductFinder.class);
when(productFactory.productFinder()).thenReturn(productFinder);
when(productFinder.updatePayApiTokenByExternalId(DEMO_PAYMENT.getExternalId(), NEW_API_TOKEN_FOR_DEMO_PAYMENT)).thenReturn(Optional.of(modifiedDemoPayment));
productApiTokenManager.replaceApiTokenForAProduct(DEMO_PAYMENT, NEW_API_TOKEN_FOR_DEMO_PAYMENT);
verifyLog(mockAppender, loggingEventArgumentCaptor, 1, String.format("Regenerated API token for product %s of type %s", modifiedDemoPayment.getExternalId(), modifiedDemoPayment.getType()));
}
use of uk.gov.pay.products.model.Product in project pay-products by alphagov.
the class ProductCreatorTest method doUpdateByGatewayAccountId_shouldNotUpdateProduct_whenNotFound.
@Test
public void doUpdateByGatewayAccountId_shouldNotUpdateProduct_whenNotFound() {
String updatedName = "updated-name";
String updatedDescription = "updated-description";
Long updatedPrice = 500L;
ProductUpdateRequest productUpdateRequest = new ProductUpdateRequest(updatedName, updatedDescription, updatedPrice, true, null, null, null);
when(productDao.findByGatewayAccountIdAndExternalId(gatewayAccountId, externalId)).thenReturn(Optional.empty());
Optional<Product> updatedProduct = productCreator.doUpdateByGatewayAccountId(gatewayAccountId, externalId, productUpdateRequest);
assertFalse(updatedProduct.isPresent());
}
use of uk.gov.pay.products.model.Product 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.model.Product 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");
}
use of uk.gov.pay.products.model.Product in project pay-products by alphagov.
the class ProductFinderTest method disableByGatewayAccountIdAndExternalId_shouldDisableProduct_whenFound.
@Test
public void disableByGatewayAccountIdAndExternalId_shouldDisableProduct_whenFound() {
Integer gatewayAccountId = 1;
String externalId = "1";
ProductEntity productEntity = new ProductEntity();
productEntity.setExternalId(externalId);
productEntity.setGatewayAccountId(gatewayAccountId);
productEntity.setReferenceEnabled(false);
when(productDao.findByGatewayAccountIdAndExternalId(gatewayAccountId, externalId)).thenReturn(Optional.of(productEntity));
Optional<Product> productOptional = productFinder.findByGatewayAccountIdAndExternalId(gatewayAccountId, externalId);
assertThat(productOptional.isPresent(), is(true));
assertThat(productOptional.get().getStatus(), is(ProductStatus.ACTIVE));
Optional<Product> disabledProduct = productFinder.disableByGatewayAccountIdAndExternalId(gatewayAccountId, externalId);
assertThat(disabledProduct.isPresent(), is(true));
assertThat(disabledProduct.get().getStatus(), is(ProductStatus.INACTIVE));
}
Aggregations