Skip to content

Commit 122b262

Browse files
committed
MC-19255: API functional tests to cover cart promotions
- added additional validation
1 parent 624ebc6 commit 122b262

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

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

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public function testCartPromotionSingleCartRule()
6565
$this->assertCount(2, $response['cart']['items']);
6666
//validating the line item prices, quantity and discount
6767
$this->assertLineItemDiscountPrices($response, $productsInCart, $qty, $ruleLabels);
68+
//total discount on the cart which is the sum of the individual row discounts
69+
$this->assertEquals($response['cart']['prices']['discounts'][0]['amount']['value'], 21.98);
6870
}
6971

7072
/**
@@ -144,7 +146,7 @@ public function testCartPromotionsMultipleCartRules()
144146
$response = $this->graphQlMutation($query);
145147
$this->assertCount(2, $response['cart']['items']);
146148

147-
//validating the individual discounts per product and aggregate discount per product
149+
//validating the individual discounts per line item and total discounts per line item
148150
$productsInResponse = array_map(null, $response['cart']['items'], $productsInCart);
149151
$count = count($productsInCart);
150152
for ($itemIndex = 0; $itemIndex < $count; $itemIndex++) {
@@ -181,6 +183,8 @@ public function testCartPromotionsMultipleCartRules()
181183
]
182184
);
183185
}
186+
$this->assertEquals($response['cart']['prices']['discounts'][0]['amount']['value'], 21.98);
187+
$this->assertEquals($response['cart']['prices']['discounts'][1]['amount']['value'], 2.2);
184188
}
185189

186190
/**
@@ -329,6 +333,28 @@ public function testCartPromotionsWithCoupons()
329333
}
330334
}
331335

336+
/**
337+
* Validating if the discount label in the response shows the default value if no label is available on cart rule
338+
*
339+
* @magentoApiDataFixture Magento/Catalog/_files/multiple_products.php
340+
* @magentoApiDataFixture Magento/SalesRule/_files/cart_rule_10_percent_off.php
341+
*/
342+
public function testCartPromotionsWithNoRuleLabels()
343+
{
344+
$skus =['simple1', 'simple2'];
345+
$qty = 1;
346+
$cartId = $this->createEmptyCart();
347+
$this->addMultipleSimpleProductsToCart($cartId, $qty, $skus[0], $skus[1]);
348+
$query = $this->getCartItemPricesQuery($cartId);
349+
$response = $this->graphQlMutation($query);
350+
//total items added to cart
351+
$this->assertCount(2, $response['cart']['items']);
352+
//checking the default label for individual line item when cart rule doesn't have a label set
353+
foreach ($response['cart']['items'] as $cartItem) {
354+
$this->assertEquals('Discount', $cartItem['prices']['discounts'][0]['label']);
355+
}
356+
}
357+
332358
/**
333359
* Apply coupon to the cart
334360
*
@@ -362,25 +388,36 @@ private function getCartItemPricesQuery(string $cartId): string
362388
{
363389
return <<<QUERY
364390
{
365-
cart(cart_id:"{$cartId}"){
391+
cart(cart_id:"$cartId"){
366392
items{
367393
quantity
394+
368395
prices{
369396
row_total{
370397
value
398+
371399
}
372400
row_total_including_tax{
373401
value
374402
}
375-
discount{value}
403+
discount{
404+
value
405+
}
376406
discounts{
377407
amount{value}
378408
label
409+
379410
}
380411
}
381412
}
413+
prices{
414+
discounts{
415+
amount{value}
416+
}
417+
382418
}
383419
}
420+
}
384421
385422
QUERY;
386423
}

0 commit comments

Comments
 (0)