Skip to content

Commit 3cd2bd8

Browse files
committed
GraphQL-191: Resolve random fails on Bamboo with \Magento\GraphQl\Quote\CouponTest::testApplyCouponToCartWithNoItems
1 parent da14c7a commit 3cd2bd8

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
7575
try {
7676
$this->couponManagement->set($cartId, $couponCode);
7777
} catch (NoSuchEntityException $e) {
78-
throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e);
78+
$message = $e->getMessage();
79+
if (preg_match('/The "\d+" Cart doesn\'t contain products/', $message)) {
80+
$message = 'Cart does not contain products.';
81+
}
82+
throw new GraphQlNoSuchEntityException(__($message), $e);
7983
} catch (CouldNotSaveException $e) {
8084
throw new LocalizedException(__($e->getMessage()), $e);
8185
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,17 @@ public function testApplyCouponTwice()
8989
/**
9090
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
9191
* @magentoApiDataFixture Magento/SalesRule/_files/coupon_code_with_wildcard.php
92+
* @expectedException \Exception
93+
* @expectedExceptionMessage Cart does not contain products.
9294
*/
9395
public function testApplyCouponToCartWithNoItems()
9496
{
9597
$couponCode = '2?ds5!2d';
9698

9799
$this->quoteResource->load($this->quote, 'test_order_1', 'reserved_order_id');
98-
$cartId = (int)$this->quote->getId();
99-
$maskedQuoteId = $this->quoteIdToMaskedId->execute($cartId);
100+
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId());
100101
$query = $this->prepareAddCouponRequestQuery($maskedQuoteId, $couponCode);
101102

102-
self::expectExceptionMessage(
103-
'The "' . $cartId . '" Cart doesn\'t contain products.'
104-
);
105103
$this->graphQlQuery($query);
106104
}
107105

0 commit comments

Comments
 (0)