Skip to content

Commit

Permalink
graphQl-784: added guest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy Boyko committed Jul 25, 2019
1 parent 28c5a88 commit e9b6334
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __construct(
public function createBasedOnInputData(array $addressInput): QuoteAddress
{
$addressInput['country_id'] = $addressInput['country_code'] ?? '';
if ($addressInput['country_id'] && !ctype_upper($addressInput['country_code'] )) {
if ($addressInput['country_id'] && !ctype_upper($addressInput['country_code'])) {
throw new GraphQlInputException(
__('"Country Code" cannot contain lowercase characters.')
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ public function testSetNewBillingAddressWithRedundantStreetLine()
* @expectedException \Exception
* @expectedExceptionMessage "Country Code" cannot contain lowercase characters.
*/
public function testSetNewBillingAddressWithLowercaseCountryCode()
public function testSetBillingAddressWithLowerCaseCountry()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,59 +602,6 @@ 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']);
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
Expand All @@ -663,7 +610,7 @@ public function testSetShippingAddressWithLowerCaseCountry()
* @expectedException \Exception
* @expectedExceptionMessage "Country Code" cannot contain lowercase characters.
*/
public function testSetNewShippingAddressOnCartWithLowercaseCountryCode()
public function testSetShippingAddressWithLowerCaseCountry()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,49 @@ 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
* @expectedException \Exception
* @expectedExceptionMessage "Country Code" cannot contain lowercase characters.
*/
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
}
}
}
}
QUERY;
$this->graphQlMutation($query);
}

/**
* 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 @@ -411,6 +411,8 @@ 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 @@ -450,13 +452,7 @@ public function testSetShippingAddressWithLowerCaseCountry()
}
}
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']);
$this->graphQlMutation($query);
}

/**
Expand Down

0 comments on commit e9b6334

Please sign in to comment.