Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

#981 Extend test coverage for BraintreeGraphQl #983

Merged
merged 1 commit into from
Oct 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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