Skip to content

Commit

Permalink
graphQl-784: removed validation, added the text convert instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy Boyko committed Jul 25, 2019
1 parent e9b6334 commit 9078004
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,10 @@ public function __construct(
*/
public function createBasedOnInputData(array $addressInput): QuoteAddress
{
$addressInput['country_id'] = $addressInput['country_code'] ?? '';
if ($addressInput['country_id'] && !ctype_upper($addressInput['country_code'])) {
throw new GraphQlInputException(
__('"Country Code" cannot contain lowercase characters.')
);
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 @@ -642,8 +642,6 @@ public function testSetNewBillingAddressWithRedundantStreetLine()
* @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
* @expectedException \Exception
* @expectedExceptionMessage "Country Code" cannot contain lowercase characters.
*/
public function testSetBillingAddressWithLowerCaseCountry()
{
Expand Down Expand Up @@ -673,12 +671,29 @@ public function testSetBillingAddressWithLowerCaseCountry()
cart {
billing_address {
firstname
lastname
company
street
city
postcode
telephone
country {
code
label
}
__typename
}
}
}
}
QUERY;
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
$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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,6 @@ public function testSetShippingAddressToGuestCart()
* @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
* @expectedException \Exception
* @expectedExceptionMessage "Country Code" cannot contain lowercase characters.
*/
public function testSetShippingAddressWithLowerCaseCountry()
{
Expand All @@ -618,34 +616,43 @@ public function testSetShippingAddressWithLowerCaseCountry()
mutation {
setShippingAddressesOnCart(
input: {
cart_id: "$maskedQuoteId"
cart_id: "{$maskedQuoteId}"
shipping_addresses: [
{
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"
firstname: "John"
lastname: "Doe"
street: ["6161 West Centinella Avenue"]
city: "Culver City"
region: "CA"
postcode: "90230"
country_code: "us"
telephone: "88776655"
save_in_address_book: false
telephone: "555-555-55-55"
}
}
]
}
) {
cart {
shipping_addresses {
firstname
region {
code
}
country {
code
}
}
}
}
}
QUERY;
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
$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']);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,6 @@ public function testSetNewBillingAddressRedundantStreetLine()
* @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
* @expectedException \Exception
* @expectedExceptionMessage "Country Code" cannot contain lowercase characters.
*/
public function testSetBillingAddressWithLowerCaseCountry()
{
Expand All @@ -472,7 +470,7 @@ public function testSetBillingAddressWithLowerCaseCountry()
input: {
cart_id: "$maskedQuoteId"
billing_address: {
address: {
address: {
firstname: "test firstname"
lastname: "test lastname"
company: "test company"
Expand All @@ -483,19 +481,36 @@ public function testSetBillingAddressWithLowerCaseCountry()
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;
$this->graphQlMutation($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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,6 @@ public function testSetShippingAddressOnNonExistentCart()
* @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
* @expectedException \Exception
* @expectedExceptionMessage "Country Code" cannot contain lowercase characters.
*/
public function testSetShippingAddressWithLowerCaseCountry()
{
Expand Down Expand Up @@ -452,7 +450,13 @@ public function testSetShippingAddressWithLowerCaseCountry()
}
}
QUERY;
$this->graphQlMutation($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']);
}

/**
Expand Down

0 comments on commit 9078004

Please sign in to comment.