Skip to content

Commit 100c963

Browse files
committed
Merge branch 'MC-42903-PR' into MC-42903
# Conflicts: # dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php
2 parents 1ef000c + ef80020 commit 100c963

File tree

4 files changed

+190
-5
lines changed

4 files changed

+190
-5
lines changed

app/code/Magento/QuoteGraphQl/etc/schema.graphqls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ input CartAddressInput {
118118
region_id: Int
119119
postcode: String
120120
country_code: String!
121-
telephone: String!
121+
telephone: String
122122
save_in_address_book: Boolean @doc(description: "Determines whether to save the address in the customer's address book. The default value is true")
123123
}
124124

@@ -224,7 +224,7 @@ interface CartAddressInterface @typeResolver(class: "\\Magento\\QuoteGraphQl\\Mo
224224
region: CartAddressRegion
225225
postcode: String
226226
country: CartAddressCountry!
227-
telephone: String!
227+
telephone: String
228228
}
229229

230230
type ShippingCartAddress implements CartAddressInterface {

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

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ private function getQuery(string $maskedQuoteId): string
164164
company
165165
street
166166
city
167-
region
167+
region
168168
{
169169
code
170170
label
171171
}
172172
postcode
173-
country
173+
country
174174
{
175175
code
176176
label
@@ -195,4 +195,44 @@ private function getHeaderMap(string $username = 'customer@example.com', string
195195
$headerMap = ['Authorization' => 'Bearer ' . $customerToken];
196196
return $headerMap;
197197
}
198+
199+
/**
200+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
201+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
202+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
203+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
204+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address_without_telephone.php
205+
*/
206+
public function testGetSpecifiedBillingAddressWithoutTelephone()
207+
{
208+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
209+
$query = $this->getQuery($maskedQuoteId);
210+
211+
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap());
212+
self::assertArrayHasKey('cart', $response);
213+
self::assertArrayHasKey('billing_address', $response['cart']);
214+
215+
$expectedBillingAddressData = [
216+
'firstname' => 'John',
217+
'lastname' => 'Smith',
218+
'company' => 'CompanyName',
219+
'street' => [
220+
'Green str, 67'
221+
],
222+
'city' => 'CityM',
223+
'region' => [
224+
'code' => 'AL',
225+
'label' => 'Alabama',
226+
],
227+
'postcode' => '75477',
228+
'country' => [
229+
'code' => 'US',
230+
'label' => 'US',
231+
],
232+
'telephone' => '',
233+
'__typename' => 'BillingCartAddress',
234+
'customer_notes' => null,
235+
];
236+
self::assertEquals($expectedBillingAddressData, $response['cart']['billing_address']);
237+
}
198238
}

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

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ public function testSetNewBillingAddressWithoutCustomerAddressIdAndAddress()
418418
QUERY;
419419

420420
self::expectExceptionMessage(
421-
'The billing address must contain either "customer_address_id", "address", or "same_as_shipping".'
421+
'The billing address must contain either "customer_address_id", "address", or "same_as_shipping".'
422422
);
423423
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
424424
}
@@ -1919,4 +1919,105 @@ public function testSetBillingAddressAndPlaceOrderWithGuestCheckoutDisabled()
19191919
{
19201920
$this->testSetBillingAddressAndPlaceOrder();
19211921
}
1922+
1923+
/**
1924+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
1925+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
1926+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
1927+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
1928+
*/
1929+
public function testSetNewBillingAddressWithoutTelephone()
1930+
{
1931+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
1932+
1933+
$query = <<<QUERY
1934+
mutation {
1935+
setBillingAddressOnCart(
1936+
input: {
1937+
cart_id: "$maskedQuoteId"
1938+
billing_address: {
1939+
address: {
1940+
firstname: "test firstname"
1941+
lastname: "test lastname"
1942+
company: "test company"
1943+
street: ["test street 1", "test street 2"]
1944+
city: "test city"
1945+
region: "AZ"
1946+
postcode: "887766"
1947+
country_code: "US"
1948+
telephone: ""
1949+
}
1950+
same_as_shipping: true
1951+
}
1952+
}
1953+
) {
1954+
cart {
1955+
billing_address {
1956+
firstname
1957+
lastname
1958+
company
1959+
street
1960+
city
1961+
postcode
1962+
telephone
1963+
country {
1964+
code
1965+
label
1966+
}
1967+
__typename
1968+
}
1969+
shipping_addresses {
1970+
firstname
1971+
lastname
1972+
company
1973+
street
1974+
city
1975+
postcode
1976+
telephone
1977+
country {
1978+
code
1979+
label
1980+
}
1981+
__typename
1982+
}
1983+
}
1984+
}
1985+
}
1986+
QUERY;
1987+
$response = $this->graphQlMutation($query, [], '', $this->getHeaderMap());
1988+
1989+
self::assertArrayHasKey('cart', $response['setBillingAddressOnCart']);
1990+
$cartResponse = $response['setBillingAddressOnCart']['cart'];
1991+
self::assertArrayHasKey('billing_address', $cartResponse);
1992+
$billingAddressResponse = $cartResponse['billing_address'];
1993+
self::assertArrayHasKey('shipping_addresses', $cartResponse);
1994+
$shippingAddressResponse = current($cartResponse['shipping_addresses']);
1995+
$this->assertNewAddressWithoutTelephone($billingAddressResponse);
1996+
$this->assertNewAddressWithoutTelephone($shippingAddressResponse, 'ShippingCartAddress');
1997+
}
1998+
1999+
/**
2000+
* Verify the all the whitelisted fields for a New Address Object without telephone
2001+
*
2002+
* @param array $addressResponse
2003+
* @param string $addressType
2004+
*/
2005+
private function assertNewAddressWithoutTelephone(
2006+
array $addressResponse,
2007+
string $addressType = 'BillingCartAddress'
2008+
): void {
2009+
$assertionMap = [
2010+
['response_field' => 'firstname', 'expected_value' => 'test firstname'],
2011+
['response_field' => 'lastname', 'expected_value' => 'test lastname'],
2012+
['response_field' => 'company', 'expected_value' => 'test company'],
2013+
['response_field' => 'street', 'expected_value' => [0 => 'test street 1', 1 => 'test street 2']],
2014+
['response_field' => 'city', 'expected_value' => 'test city'],
2015+
['response_field' => 'postcode', 'expected_value' => '887766'],
2016+
['response_field' => 'telephone', 'expected_value' => ''],
2017+
['response_field' => 'country', 'expected_value' => ['code' => 'US', 'label' => 'US']],
2018+
['response_field' => '__typename', 'expected_value' => $addressType]
2019+
];
2020+
2021+
$this->assertResponseFields($addressResponse, $assertionMap);
2022+
}
19222023
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
use Magento\Framework\Api\DataObjectHelper;
9+
use Magento\Quote\Api\Data\AddressInterface;
10+
use Magento\Quote\Api\Data\AddressInterfaceFactory;
11+
use Magento\Quote\Api\BillingAddressManagementInterface;
12+
use Magento\Quote\Model\QuoteFactory;
13+
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
14+
15+
use Magento\TestFramework\Helper\Bootstrap;
16+
17+
/** @var QuoteFactory $quoteFactory */
18+
$quoteFactory = Bootstrap::getObjectManager()->get(QuoteFactory::class);
19+
/** @var QuoteResource $quoteResource */
20+
$quoteResource = Bootstrap::getObjectManager()->get(QuoteResource::class);
21+
/** @var AddressInterfaceFactory $quoteAddressFactory */
22+
$quoteAddressFactory = Bootstrap::getObjectManager()->get(AddressInterfaceFactory::class);
23+
/** @var DataObjectHelper $dataObjectHelper */
24+
$dataObjectHelper = Bootstrap::getObjectManager()->get(DataObjectHelper::class);
25+
/** @var BillingAddressManagementInterface $billingAddressManagement */
26+
$billingAddressManagement = Bootstrap::getObjectManager()->get(BillingAddressManagementInterface::class);
27+
28+
$quoteAddressData = [
29+
AddressInterface::KEY_TELEPHONE => '',
30+
AddressInterface::KEY_POSTCODE => 75477,
31+
AddressInterface::KEY_COUNTRY_ID => 'US',
32+
AddressInterface::KEY_CITY => 'CityM',
33+
AddressInterface::KEY_COMPANY => 'CompanyName',
34+
AddressInterface::KEY_STREET => 'Green str, 67',
35+
AddressInterface::KEY_LASTNAME => 'Smith',
36+
AddressInterface::KEY_FIRSTNAME => 'John',
37+
AddressInterface::KEY_REGION_ID => 1,
38+
];
39+
$quoteAddress = $quoteAddressFactory->create();
40+
$dataObjectHelper->populateWithArray($quoteAddress, $quoteAddressData, AddressInterfaceFactory::class);
41+
42+
$quote = $quoteFactory->create();
43+
$quoteResource->load($quote, 'test_quote', 'reserved_order_id');
44+
$billingAddressManagement->assign($quote->getId(), $quoteAddress);

0 commit comments

Comments
 (0)