Skip to content

Commit e627992

Browse files
committed
530 - [Cart Operations] Update Cart Items validation messages
1. Add necessary tests
1 parent 1267436 commit e627992

File tree

4 files changed

+82
-2
lines changed

4 files changed

+82
-2
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogInventory/AddProductToCartTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,25 @@ public function testAddMoreProductsThatAllowed()
7878
self::fail('Should be "The most you may purchase is 5." error message.');
7979
}
8080

81+
/**
82+
* @magentoApiDataFixture Magento/Catalog/_files/products.php
83+
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
84+
*/
85+
public function testAddProductIfQuantityIsDecimal()
86+
{
87+
$sku = 'simple';
88+
$qty = 0.2;
89+
90+
$maskedQuoteId = $this->getMaskedQuoteId();
91+
$query = $this->getAddSimpleProductQuery($maskedQuoteId, $sku, $qty);
92+
93+
$this->expectExceptionMessage(
94+
"Could not add the product with SKU {$sku} to the shopping cart: The fewest you may purchase is 1."
95+
);
96+
97+
$this->graphQlQuery($query);
98+
}
99+
81100
/**
82101
* @return string
83102
*/
@@ -95,7 +114,7 @@ public function getMaskedQuoteId() : string
95114
* @param int $qty
96115
* @return string
97116
*/
98-
public function getAddSimpleProductQuery(string $maskedQuoteId, string $sku, int $qty) : string
117+
public function getAddSimpleProductQuery(string $maskedQuoteId, string $sku, float $qty) : string
99118
{
100119
return <<<QUERY
101120
mutation {

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/AddSimpleProductToCartTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,25 @@ public function testAddSimpleProductToCart()
5959
self::assertEquals($sku, $response['addSimpleProductsToCart']['cart']['items'][0]['product']['sku']);
6060
}
6161

62+
/**
63+
* @magentoApiDataFixture Magento/Catalog/_files/products.php
64+
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
65+
*/
66+
public function testAddSimpleProductToCartWithDecimalQty()
67+
{
68+
$sku = 'simple';
69+
$qty = 0.5;
70+
$maskedQuoteId = $this->getMaskedQuoteId();
71+
72+
$query = $this->getAddSimpleProductQuery($maskedQuoteId, $sku, $qty);
73+
74+
$this->expectExceptionMessage(
75+
"Could not add the product with SKU {$sku} to the shopping cart: The fewest you may purchase is 1."
76+
);
77+
78+
$this->graphQlQuery($query);
79+
}
80+
6281
/**
6382
* @return string
6483
*/
@@ -76,7 +95,7 @@ public function getMaskedQuoteId() : string
7695
* @param int $qty
7796
* @return string
7897
*/
79-
public function getAddSimpleProductQuery(string $maskedQuoteId, string $sku, int $qty): string
98+
public function getAddSimpleProductQuery(string $maskedQuoteId, string $sku, float $qty): string
8099
{
81100
return <<<QUERY
82101
mutation {

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/UpdateCartItemsTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,27 @@ public function testUpdateCartItemQty()
7979
$this->assertEquals($qty, $item['qty']);
8080
}
8181

82+
/**
83+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
84+
*/
85+
public function testUpdateCartItemDecimalQty()
86+
{
87+
$quote = $this->quoteFactory->create();
88+
$this->quoteResource->load($quote, 'test_order_1', 'reserved_order_id');
89+
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$quote->getId());
90+
$product = $this->productRepository->get('simple');
91+
92+
$itemId = (int)$quote->getItemByProduct($product)->getId();
93+
$qty = 0.5;
94+
95+
$this->expectExceptionMessage(
96+
"Could not update the product with SKU " . $product->getSku() . ": The fewest you may purchase is 1."
97+
);
98+
99+
$query = $this->getQuery($maskedQuoteId, $itemId, $qty);
100+
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
101+
}
102+
82103
/**
83104
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
84105
*/

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/UpdateCartItemsTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,27 @@ public function testUpdateCartItemQty()
7272
$this->assertEquals($qty, $item['qty']);
7373
}
7474

75+
/**
76+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
77+
*/
78+
public function testUpdateCartItemDecimalQty()
79+
{
80+
$quote = $this->quoteFactory->create();
81+
$this->quoteResource->load($quote, 'test_order_with_simple_product_without_address', 'reserved_order_id');
82+
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$quote->getId());
83+
$product = $this->productRepository->get('simple');
84+
85+
$itemId = (int)$quote->getItemByProduct($product)->getId();
86+
$qty = 0.5;
87+
88+
$this->expectExceptionMessage(
89+
"Could not update the product with SKU " . $product->getSku() . ": The fewest you may purchase is 1."
90+
);
91+
92+
$query = $this->getQuery($maskedQuoteId, $itemId, $qty);
93+
$this->graphQlQuery($query);
94+
}
95+
7596
/**
7697
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
7798
*/

0 commit comments

Comments
 (0)