Skip to content

Commit

Permalink
magento/graphql-ce#482: [Test Coverage] 'SetBillingAddressOnCart' fun…
Browse files Browse the repository at this point in the history
…ctionality
  • Loading branch information
Harniuk Bohdan committed Mar 16, 2019
1 parent 7b1cd79 commit b5803c5
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,39 @@ public function testSetBillingAddressOnNonExistentCart()
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
}

/**
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @dataProvider dataProviderSetWithoutRequiredParameters
* @param string $input
* @param string $message
* @throws \Exception
*/
public function testSetBillingAddressWithoutRequiredParameters(string $input, string $message)
{
$maskedQuoteId = $this->assignQuoteToCustomer();
$input = str_replace('cart_id_value', $maskedQuoteId, $input);

$query = <<<QUERY
mutation {
setBillingAddressOnCart(
input: {
{$input}
}
) {
cart {
billing_address {
city
}
}
}
}
QUERY;

$this->expectExceptionMessage($message);
$this->graphQlQuery($query);
}

/**
* Verify the all the whitelisted fields for a New Address Object
*
Expand Down Expand Up @@ -506,4 +539,21 @@ private function assignQuoteToCustomer(
$this->quoteResource->save($quote);
return $this->quoteIdToMaskedId->execute((int)$quote->getId());
}

/**
* @return array
*/
public function dataProviderSetWithoutRequiredParameters()
{
return [
'missed_billing_address' => [
'cart_id: "cart_id_value"',
'Field SetBillingAddressOnCartInput.billing_address of required type BillingAddressInput! was not provided.',
],
'missed_cart_id' => [
'billing_address: {}',
'Required parameter "cart_id" is missing'
]
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,38 @@ public function testSetBillingAddressOnNonExistentCart()
$this->graphQlQuery($query);
}

/**
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
* @dataProvider dataProviderSetWithoutRequiredParameters
* @param string $input
* @param string $message
* @throws \Exception
*/
public function testSetBillingAddressWithoutRequiredParameters(string $input, string $message)
{
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address');
$input = str_replace('cart_id_value', $maskedQuoteId, $input);

$query = <<<QUERY
mutation {
setBillingAddressOnCart(
input: {
{$input}
}
) {
cart {
billing_address {
city
}
}
}
}
QUERY;

$this->expectExceptionMessage($message);
$this->graphQlQuery($query);
}

/**
* Verify the all the whitelisted fields for a New Address Object
*
Expand Down Expand Up @@ -297,4 +329,21 @@ private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): str

return $this->quoteIdToMaskedId->execute((int)$quote->getId());
}

/**
* @return array
*/
public function dataProviderSetWithoutRequiredParameters()
{
return [
'missed_billing_address' => [
'cart_id: "cart_id_value"',
'Field SetBillingAddressOnCartInput.billing_address of required type BillingAddressInput! was not provided.',
],
'missed_cart_id' => [
'billing_address: {}',
'Required parameter "cart_id" is missing'
]
];
}
}

0 comments on commit b5803c5

Please sign in to comment.