@@ -65,6 +65,8 @@ public function testCartPromotionSingleCartRule()
65
65
$ this ->assertCount (2 , $ response ['cart ' ]['items ' ]);
66
66
//validating the line item prices, quantity and discount
67
67
$ 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 );
68
70
}
69
71
70
72
/**
@@ -144,7 +146,7 @@ public function testCartPromotionsMultipleCartRules()
144
146
$ response = $ this ->graphQlMutation ($ query );
145
147
$ this ->assertCount (2 , $ response ['cart ' ]['items ' ]);
146
148
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
148
150
$ productsInResponse = array_map (null , $ response ['cart ' ]['items ' ], $ productsInCart );
149
151
$ count = count ($ productsInCart );
150
152
for ($ itemIndex = 0 ; $ itemIndex < $ count ; $ itemIndex ++) {
@@ -181,6 +183,8 @@ public function testCartPromotionsMultipleCartRules()
181
183
]
182
184
);
183
185
}
186
+ $ this ->assertEquals ($ response ['cart ' ]['prices ' ]['discounts ' ][0 ]['amount ' ]['value ' ], 21.98 );
187
+ $ this ->assertEquals ($ response ['cart ' ]['prices ' ]['discounts ' ][1 ]['amount ' ]['value ' ], 2.2 );
184
188
}
185
189
186
190
/**
@@ -329,6 +333,28 @@ public function testCartPromotionsWithCoupons()
329
333
}
330
334
}
331
335
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
+
332
358
/**
333
359
* Apply coupon to the cart
334
360
*
@@ -362,25 +388,36 @@ private function getCartItemPricesQuery(string $cartId): string
362
388
{
363
389
return <<<QUERY
364
390
{
365
- cart(cart_id:" { $ cartId} "){
391
+ cart(cart_id:" $ cartId"){
366
392
items{
367
393
quantity
394
+
368
395
prices{
369
396
row_total{
370
397
value
398
+
371
399
}
372
400
row_total_including_tax{
373
401
value
374
402
}
375
- discount{value}
403
+ discount{
404
+ value
405
+ }
376
406
discounts{
377
407
amount{value}
378
408
label
409
+
379
410
}
380
411
}
381
412
}
413
+ prices{
414
+ discounts{
415
+ amount{value}
416
+ }
417
+
382
418
}
383
419
}
420
+ }
384
421
385
422
QUERY ;
386
423
}
0 commit comments