Search in sources :

Example 1 with ProductUpdateRequest

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());
}
Also used : ProductUpdateRequest(uk.gov.pay.products.model.ProductUpdateRequest) Product(uk.gov.pay.products.model.Product) Matchers.emptyOrNullString(org.hamcrest.Matchers.emptyOrNullString) Test(org.junit.Test)

Example 2 with ProductUpdateRequest

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");
}
Also used : ProductUpdateRequest(uk.gov.pay.products.model.ProductUpdateRequest) Product(uk.gov.pay.products.model.Product) ProductEntityFixture.aProductEntity(uk.gov.pay.products.fixtures.ProductEntityFixture.aProductEntity) ProductEntity(uk.gov.pay.products.persistence.entity.ProductEntity) Matchers.emptyOrNullString(org.hamcrest.Matchers.emptyOrNullString) ProductMetadata(uk.gov.pay.products.model.ProductMetadata) Test(org.junit.Test)

Example 3 with ProductUpdateRequest

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()));
}
Also used : ProductUpdateRequest(uk.gov.pay.products.model.ProductUpdateRequest) Product(uk.gov.pay.products.model.Product) ProductEntityFixture.aProductEntity(uk.gov.pay.products.fixtures.ProductEntityFixture.aProductEntity) ProductEntity(uk.gov.pay.products.persistence.entity.ProductEntity) Matchers.emptyOrNullString(org.hamcrest.Matchers.emptyOrNullString) Test(org.junit.Test)

Aggregations

Matchers.emptyOrNullString (org.hamcrest.Matchers.emptyOrNullString)3 Test (org.junit.Test)3 Product (uk.gov.pay.products.model.Product)3 ProductUpdateRequest (uk.gov.pay.products.model.ProductUpdateRequest)3 ProductEntityFixture.aProductEntity (uk.gov.pay.products.fixtures.ProductEntityFixture.aProductEntity)2 ProductEntity (uk.gov.pay.products.persistence.entity.ProductEntity)2 ProductMetadata (uk.gov.pay.products.model.ProductMetadata)1