Skip to content

Commit c4abc57

Browse files
authored
ENGCOM-6061: magento/graphql-ce#977: [Test coverage] Cover exceptions in AssignShippingAddressToCart, AssignBillingAddressToCart #996
2 parents 24ad661 + 3fb8cfc commit c4abc57

File tree

4 files changed

+100
-5
lines changed

4 files changed

+100
-5
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
@@ -879,6 +879,59 @@ public function testSetNewBillingAddressWithNotSaveInAddressBook()
879879
}
880880
}
881881

882+
/**
883+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
884+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
885+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
886+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
887+
*/
888+
public function testWithInvalidBillingAddressInput()
889+
{
890+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
891+
892+
$query = <<<QUERY
893+
mutation {
894+
setBillingAddressOnCart(
895+
input: {
896+
cart_id: "$maskedQuoteId"
897+
billing_address: {
898+
address: {
899+
firstname: "test firstname"
900+
lastname: "test lastname"
901+
company: "test company"
902+
street: ["test street 1", "test street 2"]
903+
city: "test city"
904+
region: "test region"
905+
postcode: "887766"
906+
country_code: "USS"
907+
telephone: "88776655"
908+
save_in_address_book: false
909+
}
910+
}
911+
}
912+
) {
913+
cart {
914+
billing_address {
915+
firstname
916+
lastname
917+
company
918+
street
919+
city
920+
postcode
921+
telephone
922+
country {
923+
code
924+
label
925+
}
926+
}
927+
}
928+
}
929+
}
930+
QUERY;
931+
$this->expectExceptionMessage('The address failed to save. Verify the address and try again.');
932+
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
933+
}
934+
882935
/**
883936
* Verify the all the whitelisted fields for a New Address Object
884937
*

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

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ public function testVerifyShippingAddressType()
269269

270270
/**
271271
* @magentoApiDataFixture Magento/Customer/_files/customer.php
272-
* @magentoApiDataFixture Magento/Customer/_files/customer_address.php
273272
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
274273
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
275274
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
@@ -710,6 +709,49 @@ public function testSetShippingAddressWithLowerCaseCountry()
710709
$this->assertEquals('CA', $address['region']['code']);
711710
}
712711

712+
/**
713+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
714+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
715+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
716+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
717+
*/
718+
public function testWithInvalidShippingAddressesInput()
719+
{
720+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
721+
722+
$query = <<<QUERY
723+
mutation {
724+
setShippingAddressesOnCart(
725+
input: {
726+
cart_id: "$maskedQuoteId"
727+
shipping_addresses: [
728+
{
729+
address: {
730+
firstname: "John"
731+
lastname: "Doe"
732+
street: ["6161 West Centinella Avenue"]
733+
city: "Culver City"
734+
region: "CA"
735+
postcode: "90230"
736+
country_code: "USS"
737+
telephone: "555-555-55-55"
738+
}
739+
}
740+
]
741+
}
742+
) {
743+
cart {
744+
shipping_addresses {
745+
city
746+
}
747+
}
748+
}
749+
}
750+
QUERY;
751+
$this->expectExceptionMessage('The address failed to save. Verify the address and try again.');
752+
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
753+
}
754+
713755
/**
714756
* @magentoApiDataFixture Magento/Customer/_files/customer.php
715757
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php

0 commit comments

Comments
 (0)