Skip to content

Commit

Permalink
ENGCOM-6028: #981 Extend test coverage for BraintreeGraphQl #983
Browse files Browse the repository at this point in the history
 - Merge Pull Request magento/graphql-ce#983 from TomashKhamlai/graphql-ce:issue/981
 - Merged commits:
   1. 287e906
  • Loading branch information
magento-engcom-team committed Oct 7, 2019
2 parents db0dce6 + 287e906 commit b3ea385
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class CreateBraintreeClientTokenTest extends GraphQlAbstract
* @magentoConfigFixture default_store payment/braintree/active 1
* @magentoConfigFixture default_store payment/braintree/environment sandbox
* @magentoConfigFixture default_store payment/braintree/merchant_id def_merchant_id
* @magentoConfigFixture default_store payment/braintree/merchant_account_id def_merchant_id
* @magentoConfigFixture default_store payment/braintree/public_key def_public_key
* @magentoConfigFixture default_store payment/braintree/private_key def_private_key
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Magento\GraphQl\Braintree\Customer;

use Magento\Braintree\Gateway\Command\GetPaymentNonceCommand;
use Magento\Framework\Exception\AuthenticationException;
use Magento\Framework\Registry;
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
use Magento\Integration\Api\CustomerTokenServiceInterface;
Expand Down Expand Up @@ -261,6 +262,34 @@ public function testSetPaymentMethodInvalidMethodInput(string $methodCode)
$this->graphQlMutation($setPaymentQuery, [], '', $this->getHeaderMap());
}

/**
* @magentoConfigFixture default_store carriers/flatrate/active 1
* @magentoConfigFixture default_store payment/braintree/active 1
* @magentoConfigFixture default_store payment/braintree_cc_vault/active 1
* @magentoConfigFixture default_store payment/braintree/environment sandbox
* @magentoConfigFixture default_store payment/braintree/merchant_id def_merchant_id
* @magentoConfigFixture default_store payment/braintree/public_key def_public_key
* @magentoConfigFixture default_store payment/braintree/private_key def_private_key
* @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
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
* @dataProvider dataProviderTestSetPaymentMethodInvalidInput
* @expectedException \Exception
*/
public function testSetPaymentMethodWithoutRequiredPaymentMethodInput()
{
$reservedOrderId = 'test_quote';
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId);

$setPaymentQuery = $this->getSetPaymentBraintreeQueryInvalidPaymentMethodInput($maskedQuoteId);
$this->expectExceptionMessage("for \"braintree\" is missing.");
$this->graphQlMutation($setPaymentQuery, [], '', $this->getHeaderMap());
}

public function dataProviderTestSetPaymentMethodInvalidInput(): array
{
return [
Expand Down Expand Up @@ -371,6 +400,33 @@ private function getSetPaymentBraintreeQueryInvalidInput(string $maskedQuoteId,
QUERY;
}

/**
* @param string $maskedQuoteId
* @return string
*/
private function getSetPaymentBraintreeQueryInvalidPaymentMethodInput(string $maskedQuoteId): string
{
return <<<QUERY
mutation {
setPaymentMethodOnCart(input:{
cart_id:"{$maskedQuoteId}"
payment_method:{
code:"braintree"
braintree:{
payment_method_nonce:"fake-valid-nonce"
}
}
}) {
cart {
selected_payment_method {
code
}
}
}
}
QUERY;
}

/**
* @param string $maskedQuoteId
* @param string $methodCode
Expand Down Expand Up @@ -437,7 +493,7 @@ private function getPaymentTokenQuery(): string
* @param string $username
* @param string $password
* @return array
* @throws \Magento\Framework\Exception\AuthenticationException
* @throws AuthenticationException
*/
private function getHeaderMap(string $username = '[email protected]', string $password = 'password'): array
{
Expand Down

0 comments on commit b3ea385

Please sign in to comment.