Skip to content

Commit 55c8382

Browse files
committed
ACP2E-910: fix failing webapi tests and static tests
1 parent 29bacd0 commit 55c8382

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

app/code/Magento/QuoteGraphQl/Model/Resolver/Discounts.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ private function getDiscountValues(Quote $quote)
4242
$discountValues=[];
4343
$address = $quote->getShippingAddress();
4444
$totals = $address->getTotals();
45-
if ($totals && is_array($totals)){
45+
if ($totals && is_array($totals)) {
4646
foreach ($totals as $total) {
4747
if (stripos($total->getCode(), 'total') === false && $total->getValue() < 0.00) {
4848
$discount = [];
4949
$amount = [];
5050
$discount['label'] = $total->getTitle() ?: __('Discount');
51-
$amount['value'] = $total->getValue();
51+
$amount['value'] = $total->getValue() * -1;
5252
$amount['currency'] = $quote->getQuoteCurrencyCode();
5353
$discount['amount'] = $amount;
5454
$discountValues[] = $discount;

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
use Magento\Catalog\Api\CategoryLinkManagementInterface;
1111
use Magento\Catalog\Api\ProductRepositoryInterface;
1212
use Magento\Catalog\Model\Product;
13+
use Magento\SalesRule\Api\RuleRepositoryInterface;
1314
use Magento\SalesRule\Model\ResourceModel\Rule\Collection;
1415
use Magento\SalesRule\Model\Rule;
15-
use Magento\TestFramework\Helper\Bootstrap;
16-
use Magento\TestFramework\TestCase\GraphQlAbstract;
1716
use Magento\Tax\Model\ClassModel as TaxClassModel;
1817
use Magento\Tax\Model\ResourceModel\TaxClass\CollectionFactory as TaxClassCollectionFactory;
19-
use Magento\SalesRule\Api\RuleRepositoryInterface;
18+
use Magento\TestFramework\Helper\Bootstrap;
19+
use Magento\TestFramework\TestCase\GraphQlAbstract;
2020

2121
/**
2222
* Test cases for applying cart promotions to items in cart
@@ -91,8 +91,7 @@ private function assertLineItemDiscountPrices($response, $productsInCart, $qty,
9191
'total_item_discount' => ['value' => $productsInCart[$itemIndex]->getSpecialPrice()*$qty*0.5],
9292
'discounts' => [
9393
0 =>[
94-
'amount' =>
95-
['value' => $productsInCart[$itemIndex]->getSpecialPrice()*$qty*0.5],
94+
'amount' => ['value' => $productsInCart[$itemIndex]->getSpecialPrice()*$qty*0.5],
9695
'label' => $ruleLabels[0]
9796
]
9897
]
@@ -108,6 +107,7 @@ private function assertLineItemDiscountPrices($response, $productsInCart, $qty,
108107
* @magentoApiDataFixture Magento/Catalog/_files/multiple_products.php
109108
* @magentoApiDataFixture Magento/SalesRule/_files/rules_category.php
110109
* @magentoApiDataFixture Magento/SalesRule/_files/cart_rule_10_percent_off_qty_more_than_2_items.php
110+
* @magentoApiDataFixture Magento/SalesRule/_files/cart_rule_free_shipping.php
111111
*/
112112
public function testCartPromotionsMultipleCartRules()
113113
{
@@ -138,6 +138,7 @@ public function testCartPromotionsMultipleCartRules()
138138
$qty = 2;
139139
$cartId = $this->createEmptyCart();
140140
$this->addMultipleSimpleProductsToCart($cartId, $qty, $skus[0], $skus[1]);
141+
$this->setShippingAddressOnCart($cartId);
141142
$query = $this->getCartItemPricesQuery($cartId);
142143
$response = $this->graphQlMutation($query);
143144
$this->assertCount(2, $response['cart']['items']);
@@ -179,8 +180,7 @@ public function testCartPromotionsMultipleCartRules()
179180
]
180181
);
181182
}
182-
$this->assertEquals($response['cart']['prices']['discounts'][0]['amount']['value'], 21.98);
183-
$this->assertEquals($response['cart']['prices']['discounts'][1]['amount']['value'], 2.2);
183+
$this->assertEquals($response['cart']['prices']['discounts'][0]['amount']['value'], 24.18);
184184
}
185185

186186
/**
@@ -255,8 +255,7 @@ public function testCartPromotionsCartRulesWithTaxes()
255255
'total_item_discount' => ['value' => round($rowTotalIncludingTax/2, 2)],
256256
'discounts' => [
257257
0 =>[
258-
'amount' =>
259-
['value' => round($rowTotalIncludingTax/2, 2)],
258+
'amount' => ['value' => round($rowTotalIncludingTax/2, 2)],
260259
'label' => 'TestRule_Label'
261260
]
262261
]
@@ -318,8 +317,7 @@ public function testCartPromotionsWithCoupons()
318317
'total_item_discount' => ['value' => round(($rowTotal/$sumOfPricesForBothProducts)*5, 2)],
319318
'discounts' => [
320319
0 =>[
321-
'amount' =>
322-
['value' => round(($rowTotal/$sumOfPricesForBothProducts)*5, 2)],
320+
'amount' => ['value' => round(($rowTotal/$sumOfPricesForBothProducts)*5, 2)],
323321
'label' => $ruleLabels[0]
324322
]
325323
]
@@ -425,8 +423,7 @@ public function testCartPromotionsFixedDiscountNotHigherThanProductsPrice()
425423
'total_item_discount' => ['value' => $rowTotal],
426424
'discounts' => [
427425
0 =>[
428-
'amount' =>
429-
['value' => $rowTotal],
426+
'amount' => ['value' => $rowTotal],
430427
'label' => $ruleLabels[0]
431428
]
432429
]

0 commit comments

Comments
 (0)