Skip to content

Commit 509b15f

Browse files
authored
ENGCOM-7659: magento/magento2#: GraphQl. setShippingAddressesOnCart. Test coverage for The shipping address must contain either "customer_address_id" or "address". error. #28492
2 parents 548f012 + c2ecf27 commit 509b15f

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ public function execute(ContextInterface $context, CartInterface $cart, array $s
5151
$shippingAddressInput = current($shippingAddressesInput) ?? [];
5252
$customerAddressId = $shippingAddressInput['customer_address_id'] ?? null;
5353

54-
if (!$customerAddressId && !isset($shippingAddressInput['address']['save_in_address_book'])) {
54+
if (!$customerAddressId
55+
&& isset($shippingAddressInput['address'])
56+
&& !isset($shippingAddressInput['address']['save_in_address_book'])
57+
) {
5558
$shippingAddressInput['address']['save_in_address_book'] = true;
5659
}
5760

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,6 +1745,57 @@ public function testSetNewShippingAddressWithDefaultValueOfSaveInAddressBookAndP
17451745
}
17461746
}
17471747

1748+
/**
1749+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
1750+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
1751+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
1752+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
1753+
*/
1754+
public function testSetShippingAddressOnCartWithNullCustomerAddressId()
1755+
{
1756+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
1757+
1758+
$query = <<<QUERY
1759+
mutation {
1760+
setShippingAddressesOnCart(
1761+
input: {
1762+
cart_id: "$maskedQuoteId"
1763+
shipping_addresses: [
1764+
{
1765+
customer_address_id: null
1766+
}
1767+
]
1768+
}
1769+
) {
1770+
cart {
1771+
shipping_addresses {
1772+
firstname
1773+
lastname
1774+
company
1775+
street
1776+
city
1777+
postcode
1778+
telephone
1779+
country {
1780+
label
1781+
code
1782+
}
1783+
region {
1784+
code
1785+
label
1786+
}
1787+
__typename
1788+
}
1789+
}
1790+
}
1791+
}
1792+
QUERY;
1793+
$this->expectExceptionMessage(
1794+
'The shipping address must contain either "customer_address_id" or "address".'
1795+
);
1796+
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
1797+
}
1798+
17481799
/**
17491800
* Verify the all the whitelisted fields for a New Address Object
17501801
*

0 commit comments

Comments
 (0)