use of uk.gov.pay.products.model.ProductUpdateRequest 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.ProductUpdateRequest 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.ProductUpdateRequest in project pay-products by alphagov.
the class ProductCreatorTest method doUpdateByGatewayAccountId_referenceDisabled_shouldUpdateProduct.
@Test
public void doUpdateByGatewayAccountId_referenceDisabled_shouldUpdateProduct() {
String updatedName = "updated-name";
String updatedDescription = "updated-description";
Long updatedPrice = 500L;
ProductUpdateRequest productUpdateRequest = new ProductUpdateRequest(updatedName, updatedDescription, updatedPrice, true, null, null, null);
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(nullValue()));
assertThat(updatedProduct.getReferenceHint(), is(nullValue()));
assertThat(updatedProduct.getMetadata(), is(nullValue()));
}
Aggregations