Skip to content
This repository has been archived by the owner on May 20, 2019. It is now read-only.

Commit

Permalink
ENGCOM-4571: [+] added tests for SetPaymentMethodOnCart functionality…
Browse files Browse the repository at this point in the history
… #521
  • Loading branch information
naydav authored Mar 25, 2019
2 parents 0371936 + 89a0e4f commit 05c9b49
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ public function __construct(
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
if (!isset($args['input']['cart_id']) || empty($args['input']['cart_id'])) {
throw new GraphQlInputException(__('Required parameter "cart_id" is missing'));
throw new GraphQlInputException(__('Required parameter "cart_id" is missing.'));
}
$maskedCartId = $args['input']['cart_id'];

if (!isset($args['input']['payment_method']['code']) || empty($args['input']['payment_method']['code'])) {
throw new GraphQlInputException(__('Required parameter "payment_method" is missing'));
throw new GraphQlInputException(__('Required parameter "code" for "payment_method" is missing.'));
}
$paymentMethodCode = $args['input']['payment_method']['code'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,54 @@ public function testPaymentMethodOnNonExistentCart()
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
* @param string $input
* @param string $message
* @dataProvider dataProviderSetPaymentMethodWithoutRequiredParameters
*/
public function testSetPaymentMethodWithoutRequiredParameters(string $input, string $message)
{
$query = <<<QUERY
mutation {
setPaymentMethodOnCart(
input: {
{$input}
}
) {
cart {
items {
qty
}
}
}
}
QUERY;
$this->expectExceptionMessage($message);
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
}
/**
* @return array
*/
public function dataProviderSetPaymentMethodWithoutRequiredParameters(): array
{
return [
'missed_cart_id' => [
'payment_method: {code: "' . Checkmo::PAYMENT_METHOD_CHECKMO_CODE . '"}',
'Required parameter "cart_id" is missing.'
],
'missed_payment_method' => [
'cart_id: "test"',
'Required parameter "code" for "payment_method" is missing.'
],
'missed_payment_method_code' => [
'cart_id: "test", payment_method: {code: ""}',
'Required parameter "code" for "payment_method" is missing.'
],
];
}

/**
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_payment_saved.php
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,53 @@ public function testSetPaymentMethodToCustomerCart()
$this->graphQlQuery($query);
}

/**
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
* @param string $input
* @param string $message
* @dataProvider dataProviderSetPaymentMethodWithoutRequiredParameters
*/
public function testSetPaymentMethodWithoutRequiredParameters(string $input, string $message)
{
$query = <<<QUERY
mutation {
setPaymentMethodOnCart(
input: {
{$input}
}
) {
cart {
items {
qty
}
}
}
}
QUERY;
$this->expectExceptionMessage($message);
$this->graphQlQuery($query);
}
/**
* @return array
*/
public function dataProviderSetPaymentMethodWithoutRequiredParameters(): array
{
return [
'missed_cart_id' => [
'payment_method: {code: "' . Checkmo::PAYMENT_METHOD_CHECKMO_CODE . '"}',
'Required parameter "cart_id" is missing.'
],
'missed_payment_method' => [
'cart_id: "test"',
'Required parameter "code" for "payment_method" is missing.'
],
'missed_payment_method_code' => [
'cart_id: "test", payment_method: {code: ""}',
'Required parameter "code" for "payment_method" is missing.'
],
];
}

/**
* @expectedException \Exception
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
Expand Down

0 comments on commit 05c9b49

Please sign in to comment.