Skip to content

Commit

Permalink
ENGCOM-5494: graphQl-784: added validation for the lowercase country …
Browse files Browse the repository at this point in the history
…id in the quote address #790
  • Loading branch information
naydav authored Jul 29, 2019
2 parents ab7f92a + 190c540 commit 968737f
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ public function __construct(
*/
public function createBasedOnInputData(array $addressInput): QuoteAddress
{
$addressInput['country_id'] = $addressInput['country_code'] ?? '';
$addressInput['country_id'] = '';
if ($addressInput['country_code']) {
$addressInput['country_code'] = strtoupper($addressInput['country_code']);
$addressInput['country_id'] = $addressInput['country_code'];
}

$maxAllowedLineCount = $this->addressHelper->getStreetLines();
if (is_array($addressInput['street']) && count($addressInput['street']) > $maxAllowedLineCount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ 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 {
if (false === $context->getExtensionAttributes()->getIsCustomer()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,65 @@ public function testSetNewBillingAddressWithRedundantStreetLine()
$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 testSetBillingAddressWithLowerCaseCountry()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');

$query = <<<QUERY
mutation {
setBillingAddressOnCart(
input: {
cart_id: "$maskedQuoteId"
billing_address: {
address: {
firstname: "test firstname"
lastname: "test lastname"
company: "test company"
street: ["test street 1", "test street 2"]
city: "test city"
region: "test region"
postcode: "887766"
country_code: "us"
telephone: "88776655"
save_in_address_book: false
}
}
}
) {
cart {
billing_address {
firstname
lastname
company
street
city
postcode
telephone
country {
code
label
}
__typename
}
}
}
}
QUERY;
$response = $this->graphQlMutation($query, [], '', $this->getHeaderMap());

self::assertArrayHasKey('cart', $response['setBillingAddressOnCart']);
$cartResponse = $response['setBillingAddressOnCart']['cart'];
self::assertArrayHasKey('billing_address', $cartResponse);
$billingAddressResponse = $cartResponse['billing_address'];
$this->assertNewAddressFields($billingAddressResponse);
}

/**
* 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 @@ -455,6 +455,64 @@ public function testSetNewBillingAddressRedundantStreetLine()
$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 testSetBillingAddressWithLowerCaseCountry()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');

$query = <<<QUERY
mutation {
setBillingAddressOnCart(
input: {
cart_id: "$maskedQuoteId"
billing_address: {
address: {
firstname: "test firstname"
lastname: "test lastname"
company: "test company"
street: ["test street 1", "test street 2"]
city: "test city"
region: "test region"
postcode: "887766"
country_code: "us"
telephone: "88776655"
save_in_address_book: false
}
}
}
) {
cart {
billing_address {
firstname
lastname
company
street
city
postcode
telephone
country {
code
label
}
__typename
}
}
}
}
QUERY;
$response = $this->graphQlMutation($query);

self::assertArrayHasKey('cart', $response['setBillingAddressOnCart']);
$cartResponse = $response['setBillingAddressOnCart']['cart'];
self::assertArrayHasKey('billing_address', $cartResponse);
$billingAddressResponse = $cartResponse['billing_address'];
$this->assertNewAddressFields($billingAddressResponse);
}

/**
* Verify the all the whitelisted fields for a New Address Object
*
Expand Down

0 comments on commit 968737f

Please sign in to comment.