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

Commit

Permalink
#977: [Test coverage] Cover exceptions in AssignShippingAddressToCart…
Browse files Browse the repository at this point in the history
…, AssignBillingAddressToCart
  • Loading branch information
atwixfirster committed Oct 9, 2019
1 parent 68c48d5 commit 26e3c20
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,51 @@ public function testSetBillingAddressWithLowerCaseCountry()
$this->assertNewAddressFields($billingAddressResponse);
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/Customer/_files/customer_address.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
* @magentoApiDataFixture Magento/Customer/_files/customer_address_set_invalid_country_id.php
*/
public function testWithInvalidBillingAddressInput()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');

$query = <<<QUERY
mutation {
setBillingAddressOnCart(
input: {
cart_id: "$maskedQuoteId"
billing_address: {
customer_address_id: 1
}
}
) {
cart {
billing_address {
firstname
lastname
company
street
city
postcode
telephone
country {
code
label
}
}
}
}
}
QUERY;

self::expectExceptionMessage('The address failed to save. Verify the address and try again.');
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
}

/**
* Verify the all the whitelisted fields for a New Address Object
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,41 @@ public function testSetShippingAddressWithLowerCaseCountry()
$this->assertEquals('CA', $address['region']['code']);
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/Customer/_files/customer_address.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
* @magentoApiDataFixture Magento/Customer/_files/customer_address_set_invalid_country_id.php
*/
public function testWithInvalidShippingAddressesInput()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');

$query = <<<QUERY
mutation {
setShippingAddressesOnCart(
input: {
cart_id: "$maskedQuoteId"
shipping_addresses: {
customer_address_id: 1
}
}
) {
cart {
shipping_addresses {
city
}
}
}
}
QUERY;

self::expectExceptionMessage('The address failed to save. Verify the address and try again.');
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
}

/**
* Verify the all the whitelisted fields for a New Address Object
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$resource = $objectManager->get(\Magento\Framework\App\ResourceConnection::class);
$connection = $resource->getConnection();
$entityTable = 'customer_address_entity';
$connection->query("UPDATE {$entityTable} SET `country_id` = 'USS' WHERE `entity_id` = 1");

0 comments on commit 26e3c20

Please sign in to comment.