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

magento/graphql-ce#977: [Test coverage] Cover exceptions in AssignShippingAddressToCart, AssignBillingAddressToCart #996

Merged
merged 3 commits into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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 = <<<QUERY
mutation {
setBillingAddressOnCart(
input: {
cart_id: "$maskedQuoteId"
billing_address: {
address: {
firstname: "test firstname"
lastname: "test lastname"
company: "test company"
street: ["test street 1", "test street 2"]
city: "test city"
region: "test region"
postcode: "887766"
country_code: "USS"
telephone: "88776655"
save_in_address_book: false
}
}
}
) {
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,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 = <<<QUERY
mutation {
setShippingAddressesOnCart(
input: {
cart_id: "$maskedQuoteId"
shipping_addresses: [
{
address: {
firstname: "John"
lastname: "Doe"
street: ["6161 West Centinella Avenue"]
city: "Culver City"
region: "CA"
postcode: "90230"
country_code: "USS"
telephone: "555-555-55-55"
}
}
]
}
) {
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