Skip to content

Commit aa9f5f1

Browse files
committed
MC-42903: GraphQL returns empty address if optional telephone is set as empty string
1 parent 100c963 commit aa9f5f1

File tree

3 files changed

+100
-1
lines changed

3 files changed

+100
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1922,6 +1922,7 @@ public function testSetBillingAddressAndPlaceOrderWithGuestCheckoutDisabled()
19221922

19231923
/**
19241924
* @magentoApiDataFixture Magento/Customer/_files/customer.php
1925+
* @magentoApiDataFixture Magento/Customer/_files/attribute_telephone_not_required_address.php
19251926
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
19261927
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
19271928
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
@@ -1947,7 +1948,7 @@ public function testSetNewBillingAddressWithoutTelephone()
19471948
country_code: "US"
19481949
telephone: ""
19491950
}
1950-
same_as_shipping: true
1951+
use_for_shipping: true
19511952
}
19521953
}
19531954
) {

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

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,4 +1963,85 @@ public function testSetNewShippingAddressAndPlaceOrderWithGuestCheckoutDisabled(
19631963
{
19641964
$this->testSetNewShippingAddressAndPlaceOrder();
19651965
}
1966+
1967+
/**
1968+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
1969+
* @magentoApiDataFixture Magento/Customer/_files/attribute_telephone_not_required_address.php
1970+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
1971+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
1972+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
1973+
*/
1974+
public function testSetNewShippingAddressWithoutTelephone()
1975+
{
1976+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
1977+
1978+
$query = <<<QUERY
1979+
mutation {
1980+
setShippingAddressesOnCart(
1981+
input: {
1982+
cart_id: "$maskedQuoteId"
1983+
shipping_addresses: {
1984+
address: {
1985+
firstname: "test firstname"
1986+
lastname: "test lastname"
1987+
company: "test company"
1988+
street: ["test street 1", "test street 2"]
1989+
city: "test city"
1990+
region: "AZ"
1991+
postcode: "887766"
1992+
country_code: "US"
1993+
telephone: ""
1994+
}
1995+
}
1996+
}
1997+
) {
1998+
cart {
1999+
shipping_addresses {
2000+
firstname
2001+
lastname
2002+
company
2003+
street
2004+
city
2005+
postcode
2006+
telephone
2007+
country {
2008+
code
2009+
label
2010+
}
2011+
__typename
2012+
}
2013+
}
2014+
}
2015+
}
2016+
QUERY;
2017+
$response = $this->graphQlMutation($query, [], '', $this->getHeaderMap());
2018+
self::assertArrayHasKey('cart', $response['setShippingAddressesOnCart']);
2019+
$cartResponse = $response['setShippingAddressesOnCart']['cart'];
2020+
self::assertArrayHasKey('shipping_addresses', $cartResponse);
2021+
$shippingAddressResponse = current($cartResponse['shipping_addresses']);
2022+
$this->assertNewAddressWithoutTelephone($shippingAddressResponse);
2023+
}
2024+
2025+
/**
2026+
* Verify the all the whitelisted fields for a New Address Object without telephone
2027+
*
2028+
* @param array $addressResponse
2029+
*/
2030+
private function assertNewAddressWithoutTelephone(
2031+
array $addressResponse
2032+
): void {
2033+
$assertionMap = [
2034+
['response_field' => 'firstname', 'expected_value' => 'test firstname'],
2035+
['response_field' => 'lastname', 'expected_value' => 'test lastname'],
2036+
['response_field' => 'company', 'expected_value' => 'test company'],
2037+
['response_field' => 'street', 'expected_value' => [0 => 'test street 1', 1 => 'test street 2']],
2038+
['response_field' => 'city', 'expected_value' => 'test city'],
2039+
['response_field' => 'postcode', 'expected_value' => '887766'],
2040+
['response_field' => 'telephone', 'expected_value' => ''],
2041+
['response_field' => 'country', 'expected_value' => ['code' => 'US', 'label' => 'US']],
2042+
['response_field' => '__typename', 'expected_value' => 'ShippingCartAddress']
2043+
];
2044+
2045+
$this->assertResponseFields($addressResponse, $assertionMap);
2046+
}
19662047
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\TestFramework\Helper\Bootstrap;
8+
use Magento\Customer\Model\Attribute;
9+
use Magento\Eav\Model\AttributeRepository;
10+
11+
/** @var Attribute $model */
12+
$attribute = Bootstrap::getObjectManager()->create(Attribute::class);
13+
/** @var AttributeRepository $attributeRepository */
14+
$attributeRepository = Bootstrap::getObjectManager()->create(AttributeRepository::class);
15+
$attribute->loadByCode('customer_address', 'telephone');
16+
$attribute->setIsRequired(false);
17+
$attributeRepository->save($attribute);

0 commit comments

Comments
 (0)