Skip to content

Commit 90557f9

Browse files
committed
magento/graphql-ce#977: [Test coverage] Cover exceptions in AssignShippingAddressToCart, AssignBillingAddressToCart
1 parent 68c48d5 commit 90557f9

File tree

4 files changed

+100
-4
lines changed

4 files changed

+100
-4
lines changed

app/code/Magento/QuoteGraphQl/Model/Cart/AssignBillingAddressToCart.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Magento\QuoteGraphQl\Model\Cart;
99

10-
use Magento\Framework\Exception\LocalizedException;
10+
use Magento\Framework\Exception\InputException;
1111
use Magento\Framework\Exception\NoSuchEntityException;
1212
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1313
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
@@ -52,7 +52,7 @@ public function execute(
5252
$this->billingAddressManagement->assign($cart->getId(), $billingAddress, $useForShipping);
5353
} catch (NoSuchEntityException $e) {
5454
throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e);
55-
} catch (LocalizedException $e) {
55+
} catch (InputException $e) {
5656
throw new GraphQlInputException(__($e->getMessage()), $e);
5757
}
5858
}

app/code/Magento/QuoteGraphQl/Model/Cart/AssignShippingAddressToCart.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Magento\QuoteGraphQl\Model\Cart;
99

10-
use Magento\Framework\Exception\LocalizedException;
10+
use Magento\Framework\Exception\InputException;
1111
use Magento\Framework\Exception\NoSuchEntityException;
1212
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1313
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
@@ -50,7 +50,7 @@ public function execute(
5050
$this->shippingAddressManagement->assign($cart->getId(), $shippingAddress);
5151
} catch (NoSuchEntityException $e) {
5252
throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e);
53-
} catch (LocalizedException $e) {
53+
} catch (InputException $e) {
5454
throw new GraphQlInputException(__($e->getMessage()), $e);
5555
}
5656
}

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,59 @@ public function testSetBillingAddressWithLowerCaseCountry()
696696
$this->assertNewAddressFields($billingAddressResponse);
697697
}
698698

699+
/**
700+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
701+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
702+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
703+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
704+
*/
705+
public function testWithInvalidBillingAddressInput()
706+
{
707+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
708+
709+
$query = <<<QUERY
710+
mutation {
711+
setBillingAddressOnCart(
712+
input: {
713+
cart_id: "$maskedQuoteId"
714+
billing_address: {
715+
address: {
716+
firstname: "test firstname"
717+
lastname: "test lastname"
718+
company: "test company"
719+
street: ["test street 1", "test street 2"]
720+
city: "test city"
721+
region: "test region"
722+
postcode: "887766"
723+
country_code: "USS"
724+
telephone: "88776655"
725+
save_in_address_book: false
726+
}
727+
}
728+
}
729+
) {
730+
cart {
731+
billing_address {
732+
firstname
733+
lastname
734+
company
735+
street
736+
city
737+
postcode
738+
telephone
739+
country {
740+
code
741+
label
742+
}
743+
}
744+
}
745+
}
746+
}
747+
QUERY;
748+
self::expectExceptionMessage('The address failed to save. Verify the address and try again.');
749+
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
750+
}
751+
699752
/**
700753
* Verify the all the whitelisted fields for a New Address Object
701754
*

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,49 @@ public function testSetShippingAddressWithLowerCaseCountry()
657657
$this->assertEquals('CA', $address['region']['code']);
658658
}
659659

660+
/**
661+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
662+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
663+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
664+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
665+
*/
666+
public function testWithInvalidShippingAddressesInput()
667+
{
668+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
669+
670+
$query = <<<QUERY
671+
mutation {
672+
setShippingAddressesOnCart(
673+
input: {
674+
cart_id: "$maskedQuoteId"
675+
shipping_addresses: [
676+
{
677+
address: {
678+
firstname: "John"
679+
lastname: "Doe"
680+
street: ["6161 West Centinella Avenue"]
681+
city: "Culver City"
682+
region: "CA"
683+
postcode: "90230"
684+
country_code: "USS"
685+
telephone: "555-555-55-55"
686+
}
687+
}
688+
]
689+
}
690+
) {
691+
cart {
692+
shipping_addresses {
693+
city
694+
}
695+
}
696+
}
697+
}
698+
QUERY;
699+
self::expectExceptionMessage('The address failed to save. Verify the address and try again.');
700+
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
701+
}
702+
660703
/**
661704
* Verify the all the whitelisted fields for a New Address Object
662705
*

0 commit comments

Comments
 (0)