Skip to content

Commit b3ea385

Browse files
ENGCOM-6028: #981 Extend test coverage for BraintreeGraphQl #983
- Merge Pull Request magento/graphql-ce#983 from TomashKhamlai/graphql-ce:issue/981 - Merged commits: 1. 287e906
2 parents db0dce6 + 287e906 commit b3ea385

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Braintree/CreateBraintreeClientTokenTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class CreateBraintreeClientTokenTest extends GraphQlAbstract
2020
* @magentoConfigFixture default_store payment/braintree/active 1
2121
* @magentoConfigFixture default_store payment/braintree/environment sandbox
2222
* @magentoConfigFixture default_store payment/braintree/merchant_id def_merchant_id
23+
* @magentoConfigFixture default_store payment/braintree/merchant_account_id def_merchant_id
2324
* @magentoConfigFixture default_store payment/braintree/public_key def_public_key
2425
* @magentoConfigFixture default_store payment/braintree/private_key def_private_key
2526
*/

dev/tests/api-functional/testsuite/Magento/GraphQl/Braintree/Customer/SetPaymentMethodTest.php

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\GraphQl\Braintree\Customer;
99

1010
use Magento\Braintree\Gateway\Command\GetPaymentNonceCommand;
11+
use Magento\Framework\Exception\AuthenticationException;
1112
use Magento\Framework\Registry;
1213
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
1314
use Magento\Integration\Api\CustomerTokenServiceInterface;
@@ -261,6 +262,34 @@ public function testSetPaymentMethodInvalidMethodInput(string $methodCode)
261262
$this->graphQlMutation($setPaymentQuery, [], '', $this->getHeaderMap());
262263
}
263264

265+
/**
266+
* @magentoConfigFixture default_store carriers/flatrate/active 1
267+
* @magentoConfigFixture default_store payment/braintree/active 1
268+
* @magentoConfigFixture default_store payment/braintree_cc_vault/active 1
269+
* @magentoConfigFixture default_store payment/braintree/environment sandbox
270+
* @magentoConfigFixture default_store payment/braintree/merchant_id def_merchant_id
271+
* @magentoConfigFixture default_store payment/braintree/public_key def_public_key
272+
* @magentoConfigFixture default_store payment/braintree/private_key def_private_key
273+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
274+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
275+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
276+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
277+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
278+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
279+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
280+
* @dataProvider dataProviderTestSetPaymentMethodInvalidInput
281+
* @expectedException \Exception
282+
*/
283+
public function testSetPaymentMethodWithoutRequiredPaymentMethodInput()
284+
{
285+
$reservedOrderId = 'test_quote';
286+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId);
287+
288+
$setPaymentQuery = $this->getSetPaymentBraintreeQueryInvalidPaymentMethodInput($maskedQuoteId);
289+
$this->expectExceptionMessage("for \"braintree\" is missing.");
290+
$this->graphQlMutation($setPaymentQuery, [], '', $this->getHeaderMap());
291+
}
292+
264293
public function dataProviderTestSetPaymentMethodInvalidInput(): array
265294
{
266295
return [
@@ -371,6 +400,33 @@ private function getSetPaymentBraintreeQueryInvalidInput(string $maskedQuoteId,
371400
QUERY;
372401
}
373402

403+
/**
404+
* @param string $maskedQuoteId
405+
* @return string
406+
*/
407+
private function getSetPaymentBraintreeQueryInvalidPaymentMethodInput(string $maskedQuoteId): string
408+
{
409+
return <<<QUERY
410+
mutation {
411+
setPaymentMethodOnCart(input:{
412+
cart_id:"{$maskedQuoteId}"
413+
payment_method:{
414+
code:"braintree"
415+
braintree:{
416+
payment_method_nonce:"fake-valid-nonce"
417+
}
418+
}
419+
}) {
420+
cart {
421+
selected_payment_method {
422+
code
423+
}
424+
}
425+
}
426+
}
427+
QUERY;
428+
}
429+
374430
/**
375431
* @param string $maskedQuoteId
376432
* @param string $methodCode
@@ -437,7 +493,7 @@ private function getPaymentTokenQuery(): string
437493
* @param string $username
438494
* @param string $password
439495
* @return array
440-
* @throws \Magento\Framework\Exception\AuthenticationException
496+
* @throws AuthenticationException
441497
*/
442498
private function getHeaderMap(string $username = '[email protected]', string $password = 'password'): array
443499
{

0 commit comments

Comments
 (0)