Skip to content

Commit 05c9b49

Browse files
authored
ENGCOM-4571: [+] added tests for SetPaymentMethodOnCart functionality #521
2 parents 0371936 + 89a0e4f commit 05c9b49

File tree

3 files changed

+97
-2
lines changed

3 files changed

+97
-2
lines changed

app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ public function __construct(
6060
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
6161
{
6262
if (!isset($args['input']['cart_id']) || empty($args['input']['cart_id'])) {
63-
throw new GraphQlInputException(__('Required parameter "cart_id" is missing'));
63+
throw new GraphQlInputException(__('Required parameter "cart_id" is missing.'));
6464
}
6565
$maskedCartId = $args['input']['cart_id'];
6666

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

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,54 @@ public function testPaymentMethodOnNonExistentCart()
171171
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
172172
}
173173

174+
/**
175+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
176+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
177+
* @param string $input
178+
* @param string $message
179+
* @dataProvider dataProviderSetPaymentMethodWithoutRequiredParameters
180+
*/
181+
public function testSetPaymentMethodWithoutRequiredParameters(string $input, string $message)
182+
{
183+
$query = <<<QUERY
184+
mutation {
185+
setPaymentMethodOnCart(
186+
input: {
187+
{$input}
188+
}
189+
) {
190+
cart {
191+
items {
192+
qty
193+
}
194+
}
195+
}
196+
}
197+
QUERY;
198+
$this->expectExceptionMessage($message);
199+
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
200+
}
201+
/**
202+
* @return array
203+
*/
204+
public function dataProviderSetPaymentMethodWithoutRequiredParameters(): array
205+
{
206+
return [
207+
'missed_cart_id' => [
208+
'payment_method: {code: "' . Checkmo::PAYMENT_METHOD_CHECKMO_CODE . '"}',
209+
'Required parameter "cart_id" is missing.'
210+
],
211+
'missed_payment_method' => [
212+
'cart_id: "test"',
213+
'Required parameter "code" for "payment_method" is missing.'
214+
],
215+
'missed_payment_method_code' => [
216+
'cart_id: "test", payment_method: {code: ""}',
217+
'Required parameter "code" for "payment_method" is missing.'
218+
],
219+
];
220+
}
221+
174222
/**
175223
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_payment_saved.php
176224
*/

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,53 @@ public function testSetPaymentMethodToCustomerCart()
126126
$this->graphQlQuery($query);
127127
}
128128

129+
/**
130+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
131+
* @param string $input
132+
* @param string $message
133+
* @dataProvider dataProviderSetPaymentMethodWithoutRequiredParameters
134+
*/
135+
public function testSetPaymentMethodWithoutRequiredParameters(string $input, string $message)
136+
{
137+
$query = <<<QUERY
138+
mutation {
139+
setPaymentMethodOnCart(
140+
input: {
141+
{$input}
142+
}
143+
) {
144+
cart {
145+
items {
146+
qty
147+
}
148+
}
149+
}
150+
}
151+
QUERY;
152+
$this->expectExceptionMessage($message);
153+
$this->graphQlQuery($query);
154+
}
155+
/**
156+
* @return array
157+
*/
158+
public function dataProviderSetPaymentMethodWithoutRequiredParameters(): array
159+
{
160+
return [
161+
'missed_cart_id' => [
162+
'payment_method: {code: "' . Checkmo::PAYMENT_METHOD_CHECKMO_CODE . '"}',
163+
'Required parameter "cart_id" is missing.'
164+
],
165+
'missed_payment_method' => [
166+
'cart_id: "test"',
167+
'Required parameter "code" for "payment_method" is missing.'
168+
],
169+
'missed_payment_method_code' => [
170+
'cart_id: "test", payment_method: {code: ""}',
171+
'Required parameter "code" for "payment_method" is missing.'
172+
],
173+
];
174+
}
175+
129176
/**
130177
* @expectedException \Exception
131178
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"

0 commit comments

Comments
 (0)