Skip to content

Commit dae8bcd

Browse files
authored
ENGCOM-5329: Transform quote address country code to uppercase #744
2 parents bcfe16f + f28aa3e commit dae8bcd

File tree

4 files changed

+159
-1
lines changed

4 files changed

+159
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public function execute(ContextInterface $context, CartInterface $cart, array $s
7474
}
7575

7676
if (null === $customerAddressId) {
77+
$addressInput['country_code'] = strtoupper($addressInput['country_code']);
7778
$shippingAddress = $this->quoteAddressFactory->createBasedOnInputData($addressInput);
7879
} else {
7980
$customer = $this->getCustomer->execute($context);

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,59 @@ public function testSetShippingAddressToGuestCart()
602602
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
603603
}
604604

605+
/**
606+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
607+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
608+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
609+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
610+
*/
611+
public function testSetShippingAddressWithLowerCaseCountry()
612+
{
613+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
614+
615+
$query = <<<QUERY
616+
mutation {
617+
setShippingAddressesOnCart(
618+
input: {
619+
cart_id: "{$maskedQuoteId}"
620+
shipping_addresses: [
621+
{
622+
address: {
623+
firstname: "John"
624+
lastname: "Doe"
625+
street: ["6161 West Centinella Avenue"]
626+
city: "Culver City"
627+
region: "CA"
628+
postcode: "90230"
629+
country_code: "us"
630+
telephone: "555-555-55-55"
631+
}
632+
}
633+
]
634+
}
635+
) {
636+
cart {
637+
shipping_addresses {
638+
region {
639+
code
640+
}
641+
country {
642+
code
643+
}
644+
}
645+
}
646+
}
647+
}
648+
QUERY;
649+
$result = $this->graphQlMutation($query, [], '', $this->getHeaderMap());
650+
651+
self::assertCount(1, $result['setShippingAddressesOnCart']['cart']['shipping_addresses']);
652+
$address = reset($result['setShippingAddressesOnCart']['cart']['shipping_addresses']);
653+
654+
$this->assertEquals('US', $address['country']['code']);
655+
$this->assertEquals('CA', $address['region']['code']);
656+
}
657+
605658
/**
606659
* Verify the all the whitelisted fields for a New Address Object
607660
*

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

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,110 @@ public function testSetShippingAddressOnNonExistentCart()
407407
$this->graphQlMutation($query);
408408
}
409409

410+
/**
411+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
412+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
413+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
414+
*/
415+
public function testSetShippingAddressWithLowerCaseCountry()
416+
{
417+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
418+
419+
$query = <<<QUERY
420+
mutation {
421+
setShippingAddressesOnCart(
422+
input: {
423+
cart_id: "{$maskedQuoteId}"
424+
shipping_addresses: [
425+
{
426+
address: {
427+
firstname: "John"
428+
lastname: "Doe"
429+
street: ["6161 West Centinella Avenue"]
430+
city: "Culver City"
431+
region: "CA"
432+
postcode: "90230"
433+
country_code: "us"
434+
telephone: "555-555-55-55"
435+
}
436+
}
437+
]
438+
}
439+
) {
440+
cart {
441+
shipping_addresses {
442+
region {
443+
code
444+
}
445+
country {
446+
code
447+
}
448+
}
449+
}
450+
}
451+
}
452+
QUERY;
453+
$result = $this->graphQlMutation($query);
454+
455+
self::assertCount(1, $result['setShippingAddressesOnCart']['cart']['shipping_addresses']);
456+
$address = reset($result['setShippingAddressesOnCart']['cart']['shipping_addresses']);
457+
458+
$this->assertEquals('US', $address['country']['code']);
459+
$this->assertEquals('CA', $address['region']['code']);
460+
}
461+
462+
/**
463+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
464+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
465+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
466+
*/
467+
public function testSetShippingAddressWithLowerCaseRegion()
468+
{
469+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
470+
471+
$query = <<<QUERY
472+
mutation {
473+
setShippingAddressesOnCart(
474+
input: {
475+
cart_id: "{$maskedQuoteId}"
476+
shipping_addresses: [
477+
{
478+
address: {
479+
firstname: "John"
480+
lastname: "Doe"
481+
street: ["6161 West Centinella Avenue"]
482+
city: "Culver City"
483+
region: "ca"
484+
postcode: "90230"
485+
country_code: "US"
486+
telephone: "555-555-55-55"
487+
}
488+
}
489+
]
490+
}
491+
) {
492+
cart {
493+
shipping_addresses {
494+
region {
495+
code
496+
}
497+
country {
498+
code
499+
}
500+
}
501+
}
502+
}
503+
}
504+
QUERY;
505+
$result = $this->graphQlMutation($query);
506+
507+
self::assertCount(1, $result['setShippingAddressesOnCart']['cart']['shipping_addresses']);
508+
$address = reset($result['setShippingAddressesOnCart']['cart']['shipping_addresses']);
509+
510+
$this->assertEquals('US', $address['country']['code']);
511+
$this->assertEquals('CA', $address['region']['code']);
512+
}
513+
410514
/**
411515
* Verify the all the whitelisted fields for a New Address Object
412516
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ public function testSetShippingMethodToCustomerCart()
331331
);
332332
$this->graphQlMutation($query);
333333
}
334-
334+
335335
/**
336336
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
337337
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php

0 commit comments

Comments
 (0)