Skip to content

Commit 968737f

Browse files
authored
ENGCOM-5494: graphQl-784: added validation for the lowercase country id in the quote address #790
2 parents ab7f92a + 190c540 commit 968737f

File tree

4 files changed

+122
-2
lines changed

4 files changed

+122
-2
lines changed

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ public function __construct(
6060
*/
6161
public function createBasedOnInputData(array $addressInput): QuoteAddress
6262
{
63-
$addressInput['country_id'] = $addressInput['country_code'] ?? '';
63+
$addressInput['country_id'] = '';
64+
if ($addressInput['country_code']) {
65+
$addressInput['country_code'] = strtoupper($addressInput['country_code']);
66+
$addressInput['country_id'] = $addressInput['country_code'];
67+
}
6468

6569
$maxAllowedLineCount = $this->addressHelper->getStreetLines();
6670
if (is_array($addressInput['street']) && count($addressInput['street']) > $maxAllowedLineCount) {

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

-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ public function execute(ContextInterface $context, CartInterface $cart, array $s
6666
}
6767

6868
if (null === $customerAddressId) {
69-
$addressInput['country_code'] = strtoupper($addressInput['country_code']);
7069
$shippingAddress = $this->quoteAddressFactory->createBasedOnInputData($addressInput);
7170
} else {
7271
if (false === $context->getExtensionAttributes()->getIsCustomer()) {

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

+59
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,65 @@ public function testSetNewBillingAddressWithRedundantStreetLine()
637637
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
638638
}
639639

640+
/**
641+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
642+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
643+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
644+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
645+
*/
646+
public function testSetBillingAddressWithLowerCaseCountry()
647+
{
648+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
649+
650+
$query = <<<QUERY
651+
mutation {
652+
setBillingAddressOnCart(
653+
input: {
654+
cart_id: "$maskedQuoteId"
655+
billing_address: {
656+
address: {
657+
firstname: "test firstname"
658+
lastname: "test lastname"
659+
company: "test company"
660+
street: ["test street 1", "test street 2"]
661+
city: "test city"
662+
region: "test region"
663+
postcode: "887766"
664+
country_code: "us"
665+
telephone: "88776655"
666+
save_in_address_book: false
667+
}
668+
}
669+
}
670+
) {
671+
cart {
672+
billing_address {
673+
firstname
674+
lastname
675+
company
676+
street
677+
city
678+
postcode
679+
telephone
680+
country {
681+
code
682+
label
683+
}
684+
__typename
685+
}
686+
}
687+
}
688+
}
689+
QUERY;
690+
$response = $this->graphQlMutation($query, [], '', $this->getHeaderMap());
691+
692+
self::assertArrayHasKey('cart', $response['setBillingAddressOnCart']);
693+
$cartResponse = $response['setBillingAddressOnCart']['cart'];
694+
self::assertArrayHasKey('billing_address', $cartResponse);
695+
$billingAddressResponse = $cartResponse['billing_address'];
696+
$this->assertNewAddressFields($billingAddressResponse);
697+
}
698+
640699
/**
641700
* Verify the all the whitelisted fields for a New Address Object
642701
*

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

+58
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,64 @@ public function testSetNewBillingAddressRedundantStreetLine()
455455
$this->graphQlMutation($query);
456456
}
457457

458+
/**
459+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
460+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
461+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
462+
*/
463+
public function testSetBillingAddressWithLowerCaseCountry()
464+
{
465+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
466+
467+
$query = <<<QUERY
468+
mutation {
469+
setBillingAddressOnCart(
470+
input: {
471+
cart_id: "$maskedQuoteId"
472+
billing_address: {
473+
address: {
474+
firstname: "test firstname"
475+
lastname: "test lastname"
476+
company: "test company"
477+
street: ["test street 1", "test street 2"]
478+
city: "test city"
479+
region: "test region"
480+
postcode: "887766"
481+
country_code: "us"
482+
telephone: "88776655"
483+
save_in_address_book: false
484+
}
485+
}
486+
}
487+
) {
488+
cart {
489+
billing_address {
490+
firstname
491+
lastname
492+
company
493+
street
494+
city
495+
postcode
496+
telephone
497+
country {
498+
code
499+
label
500+
}
501+
__typename
502+
}
503+
}
504+
}
505+
}
506+
QUERY;
507+
$response = $this->graphQlMutation($query);
508+
509+
self::assertArrayHasKey('cart', $response['setBillingAddressOnCart']);
510+
$cartResponse = $response['setBillingAddressOnCart']['cart'];
511+
self::assertArrayHasKey('billing_address', $cartResponse);
512+
$billingAddressResponse = $cartResponse['billing_address'];
513+
$this->assertNewAddressFields($billingAddressResponse);
514+
}
515+
458516
/**
459517
* Verify the all the whitelisted fields for a New Address Object
460518
*

0 commit comments

Comments
 (0)