From 90557f9c2a0c1720792d4747c9473bd2647a2ec9 Mon Sep 17 00:00:00 2001 From: Alex Taranovsky Date: Wed, 9 Oct 2019 15:17:18 +0300 Subject: [PATCH 1/2] magento/graphql-ce#977: [Test coverage] Cover exceptions in AssignShippingAddressToCart, AssignBillingAddressToCart --- .../Model/Cart/AssignBillingAddressToCart.php | 4 +- .../Cart/AssignShippingAddressToCart.php | 4 +- .../Customer/SetBillingAddressOnCartTest.php | 53 +++++++++++++++++++ .../Customer/SetShippingAddressOnCartTest.php | 43 +++++++++++++++ 4 files changed, 100 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/AssignBillingAddressToCart.php b/app/code/Magento/QuoteGraphQl/Model/Cart/AssignBillingAddressToCart.php index dd6478b4873c..95c46cdcca5d 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/AssignBillingAddressToCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/AssignBillingAddressToCart.php @@ -7,7 +7,7 @@ namespace Magento\QuoteGraphQl\Model\Cart; -use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Exception\InputException; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; @@ -52,7 +52,7 @@ public function execute( $this->billingAddressManagement->assign($cart->getId(), $billingAddress, $useForShipping); } catch (NoSuchEntityException $e) { throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e); - } catch (LocalizedException $e) { + } catch (InputException $e) { throw new GraphQlInputException(__($e->getMessage()), $e); } } diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/AssignShippingAddressToCart.php b/app/code/Magento/QuoteGraphQl/Model/Cart/AssignShippingAddressToCart.php index 527999b245a4..4dbcfad31e84 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/AssignShippingAddressToCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/AssignShippingAddressToCart.php @@ -7,7 +7,7 @@ namespace Magento\QuoteGraphQl\Model\Cart; -use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Exception\InputException; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; @@ -50,7 +50,7 @@ public function execute( $this->shippingAddressManagement->assign($cart->getId(), $shippingAddress); } catch (NoSuchEntityException $e) { throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e); - } catch (LocalizedException $e) { + } catch (InputException $e) { throw new GraphQlInputException(__($e->getMessage()), $e); } } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php index 011930e72327..16f6510dbfa2 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php @@ -696,6 +696,59 @@ public function testSetBillingAddressWithLowerCaseCountry() $this->assertNewAddressFields($billingAddressResponse); } + /** + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + */ + public function testWithInvalidBillingAddressInput() + { + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); + + $query = <<graphQlMutation($query, [], '', $this->getHeaderMap()); + } + /** * Verify the all the whitelisted fields for a New Address Object * diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingAddressOnCartTest.php index e74b7c41b398..e24de031b4a8 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingAddressOnCartTest.php @@ -657,6 +657,49 @@ public function testSetShippingAddressWithLowerCaseCountry() $this->assertEquals('CA', $address['region']['code']); } + /** + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + */ + public function testWithInvalidShippingAddressesInput() + { + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); + + $query = <<graphQlMutation($query, [], '', $this->getHeaderMap()); + } + /** * Verify the all the whitelisted fields for a New Address Object * From f49fe7195f7082f5153da92318bc7ab974e0beb0 Mon Sep 17 00:00:00 2001 From: Lena Orobei Date: Tue, 15 Oct 2019 08:22:24 -0500 Subject: [PATCH 2/2] magento/graphql-ce#977: [Test coverage] Cover exceptions in AssignShippingAddressToCart, AssignBillingAddressToCart --- .../GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php | 2 +- .../GraphQl/Quote/Customer/SetShippingAddressOnCartTest.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php index 771ce8391ec0..d4f23854378f 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php @@ -928,7 +928,7 @@ public function testWithInvalidBillingAddressInput() } } QUERY; - self::expectExceptionMessage('The address failed to save. Verify the address and try again.'); + $this->expectExceptionMessage('The address failed to save. Verify the address and try again.'); $this->graphQlMutation($query, [], '', $this->getHeaderMap()); } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingAddressOnCartTest.php index f5f9d57ea96f..8b1b678b0b3a 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingAddressOnCartTest.php @@ -748,7 +748,7 @@ public function testWithInvalidShippingAddressesInput() } } QUERY; - self::expectExceptionMessage('The address failed to save. Verify the address and try again.'); + $this->expectExceptionMessage('The address failed to save. Verify the address and try again.'); $this->graphQlMutation($query, [], '', $this->getHeaderMap()); } @@ -894,7 +894,6 @@ public function testSetNewShippingAddressWithNotSaveInAddressBook() } } - /** * Verify the all the whitelisted fields for a New Address Object *