Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

Commit 26e3c20

Browse files
committed
#977: [Test coverage] Cover exceptions in AssignShippingAddressToCart, AssignBillingAddressToCart
1 parent 68c48d5 commit 26e3c20

File tree

5 files changed

+96
-4
lines changed

5 files changed

+96
-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: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,51 @@ public function testSetBillingAddressWithLowerCaseCountry()
696696
$this->assertNewAddressFields($billingAddressResponse);
697697
}
698698

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

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

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

660+
/**
661+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
662+
* @magentoApiDataFixture Magento/Customer/_files/customer_address.php
663+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
664+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
665+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
666+
* @magentoApiDataFixture Magento/Customer/_files/customer_address_set_invalid_country_id.php
667+
*/
668+
public function testWithInvalidShippingAddressesInput()
669+
{
670+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
671+
672+
$query = <<<QUERY
673+
mutation {
674+
setShippingAddressesOnCart(
675+
input: {
676+
cart_id: "$maskedQuoteId"
677+
shipping_addresses: {
678+
customer_address_id: 1
679+
}
680+
}
681+
) {
682+
cart {
683+
shipping_addresses {
684+
city
685+
}
686+
}
687+
}
688+
}
689+
QUERY;
690+
691+
self::expectExceptionMessage('The address failed to save. Verify the address and try again.');
692+
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
693+
}
694+
660695
/**
661696
* Verify the all the whitelisted fields for a New Address Object
662697
*
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
9+
$resource = $objectManager->get(\Magento\Framework\App\ResourceConnection::class);
10+
$connection = $resource->getConnection();
11+
$entityTable = 'customer_address_entity';
12+
$connection->query("UPDATE {$entityTable} SET `country_id` = 'USS' WHERE `entity_id` = 1");

0 commit comments

Comments
 (0)