Skip to content

Commit

Permalink
ENGCOM-5329: Transform quote address country code to uppercase #744
Browse files Browse the repository at this point in the history
  • Loading branch information
naydav authored Jun 20, 2019
2 parents bcfe16f + f28aa3e commit 2140a60
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function execute(ContextInterface $context, CartInterface $cart, array $s
}

if (null === $customerAddressId) {
$addressInput['country_code'] = strtoupper($addressInput['country_code']);
$shippingAddress = $this->quoteAddressFactory->createBasedOnInputData($addressInput);
} else {
$customer = $this->getCustomer->execute($context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,59 @@ public function testSetShippingAddressToGuestCart()
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
*/
public function testSetShippingAddressWithLowerCaseCountry()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');

$query = <<<QUERY
mutation {
setShippingAddressesOnCart(
input: {
cart_id: "{$maskedQuoteId}"
shipping_addresses: [
{
address: {
firstname: "John"
lastname: "Doe"
street: ["6161 West Centinella Avenue"]
city: "Culver City"
region: "CA"
postcode: "90230"
country_code: "us"
telephone: "555-555-55-55"
}
}
]
}
) {
cart {
shipping_addresses {
region {
code
}
country {
code
}
}
}
}
}
QUERY;
$result = $this->graphQlMutation($query, [], '', $this->getHeaderMap());

self::assertCount(1, $result['setShippingAddressesOnCart']['cart']['shipping_addresses']);
$address = reset($result['setShippingAddressesOnCart']['cart']['shipping_addresses']);

$this->assertEquals('US', $address['country']['code']);
$this->assertEquals('CA', $address['region']['code']);
}

/**
* Verify the all the whitelisted fields for a New Address Object
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,110 @@ public function testSetShippingAddressOnNonExistentCart()
$this->graphQlMutation($query);
}

/**
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
*/
public function testSetShippingAddressWithLowerCaseCountry()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');

$query = <<<QUERY
mutation {
setShippingAddressesOnCart(
input: {
cart_id: "{$maskedQuoteId}"
shipping_addresses: [
{
address: {
firstname: "John"
lastname: "Doe"
street: ["6161 West Centinella Avenue"]
city: "Culver City"
region: "CA"
postcode: "90230"
country_code: "us"
telephone: "555-555-55-55"
}
}
]
}
) {
cart {
shipping_addresses {
region {
code
}
country {
code
}
}
}
}
}
QUERY;
$result = $this->graphQlMutation($query);

self::assertCount(1, $result['setShippingAddressesOnCart']['cart']['shipping_addresses']);
$address = reset($result['setShippingAddressesOnCart']['cart']['shipping_addresses']);

$this->assertEquals('US', $address['country']['code']);
$this->assertEquals('CA', $address['region']['code']);
}

/**
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
*/
public function testSetShippingAddressWithLowerCaseRegion()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');

$query = <<<QUERY
mutation {
setShippingAddressesOnCart(
input: {
cart_id: "{$maskedQuoteId}"
shipping_addresses: [
{
address: {
firstname: "John"
lastname: "Doe"
street: ["6161 West Centinella Avenue"]
city: "Culver City"
region: "ca"
postcode: "90230"
country_code: "US"
telephone: "555-555-55-55"
}
}
]
}
) {
cart {
shipping_addresses {
region {
code
}
country {
code
}
}
}
}
}
QUERY;
$result = $this->graphQlMutation($query);

self::assertCount(1, $result['setShippingAddressesOnCart']['cart']['shipping_addresses']);
$address = reset($result['setShippingAddressesOnCart']['cart']['shipping_addresses']);

$this->assertEquals('US', $address['country']['code']);
$this->assertEquals('CA', $address['region']['code']);
}

/**
* Verify the all the whitelisted fields for a New Address Object
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public function testSetShippingMethodToCustomerCart()
);
$this->graphQlMutation($query);
}

/**
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
Expand Down

0 comments on commit 2140a60

Please sign in to comment.