Skip to content

Commit 451db6c

Browse files
committed
Merge remote-tracking branch 'honey/MC-22838' into honey_tsg
2 parents 439d2ab + 1f8c1cf commit 451db6c

34 files changed

+195
-79
lines changed

app/code/Magento/CustomerGraphQl/etc/schema.graphqls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ input CustomerInput {
6161
middlename: String @doc(description: "The customer's middle name")
6262
lastname: String @doc(description: "The customer's family name")
6363
suffix: String @doc(description: "A value such as Sr., Jr., or III")
64-
email: String! @doc(description: "The customer's email address. Required")
64+
email: String @doc(description: "The customer's email address. Required for customer creation")
6565
dob: String @doc(description: "Deprecated: Use `date_of_birth` instead")
6666
date_of_birth: String @doc(description: "The customer's date of birth")
6767
taxvat: String @doc(description: "The customer's Tax/VAT number (for corporate customers)")

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,19 @@ public function dataProviderTestPlaceOrder(): array
126126
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
127127
* @dataProvider dataProviderSetPaymentInvalidInput
128128
* @param \Closure $getMutationClosure
129-
* @param string $expectedMessage
129+
* @param array $expectedMessages
130130
* @expectedException \Exception
131131
*/
132-
public function testSetPaymentInvalidInput(\Closure $getMutationClosure, string $expectedMessage)
132+
public function testSetPaymentInvalidInput(\Closure $getMutationClosure, array $expectedMessages)
133133
{
134134
$reservedOrderId = 'test_quote';
135135
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId);
136136

137137
$setPaymentMutation = $getMutationClosure($maskedQuoteId);
138138

139-
$this->expectExceptionMessage($expectedMessage);
139+
foreach ($expectedMessages as $expectedMessage) {
140+
$this->expectExceptionMessage($expectedMessage);
141+
}
140142
$this->graphQlMutation($setPaymentMutation, [], '', $this->getHeaderMap());
141143
}
142144

@@ -152,13 +154,20 @@ public function dataProviderSetPaymentInvalidInput(): array
152154
function (string $maskedQuoteId) {
153155
return $this->getInvalidSetPaymentMutation($maskedQuoteId);
154156
},
155-
'Required parameter "authorizenet_acceptjs" for "payment_method" is missing.',
157+
[
158+
'Required parameter "authorizenet_acceptjs" for "payment_method" is missing.'
159+
]
156160
],
157161
[
158162
function (string $maskedQuoteId) {
159163
return $this->getEmptyAcceptJsInput($maskedQuoteId);
160164
},
161-
'for "authorizenet_acceptjs" is missing.',
165+
[
166+
'Field AuthorizenetInput.cc_last_4 of required type Int! was not provided.',
167+
'Field AuthorizenetInput.opaque_data_descriptor of required type String! was not provided.',
168+
'Field AuthorizenetInput.opaque_data_value of required type String! was not provided.'
169+
]
170+
162171
],
163172
[
164173
function (string $maskedQuoteId) {
@@ -168,13 +177,17 @@ function (string $maskedQuoteId) {
168177
static::VALID_NONCE
169178
);
170179
},
171-
'parameter "cc_last_4" for "authorizenet_acceptjs" is missing',
180+
[
181+
'Field AuthorizenetInput.cc_last_4 of required type Int! was not provided',
182+
]
172183
],
173184
[
174185
function (string $maskedQuoteId) {
175186
return $this->getMissingOpaqueDataValueAcceptJsInput($maskedQuoteId, static::VALID_DESCRIPTOR);
176187
},
177-
'parameter "opaque_data_value" for "authorizenet_acceptjs" is missing',
188+
[
189+
'Field AuthorizenetInput.opaque_data_value of required type String! was not provided',
190+
]
178191
],
179192
];
180193
}

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,14 @@ public function testSetPaymentMethodInvalidMethodInput(string $methodCode)
259259
$methodCode
260260
);
261261
$this->expectExceptionMessage("for \"$methodCode\" is missing.");
262+
$expectedExceptionMessages = [
263+
'braintree' =>
264+
'Field BraintreeInput.is_active_payment_token_enabler of required type Boolean! was not provided.',
265+
'braintree_cc_vault' =>
266+
'Field BraintreeCcVaultInput.public_hash of required type String! was not provided.'
267+
];
268+
269+
$this->expectExceptionMessage($expectedExceptionMessages[$methodCode]);
262270
$this->graphQlMutation($setPaymentQuery, [], '', $this->getHeaderMap());
263271
}
264272

@@ -277,7 +285,6 @@ public function testSetPaymentMethodInvalidMethodInput(string $methodCode)
277285
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
278286
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
279287
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
280-
* @dataProvider dataProviderTestSetPaymentMethodInvalidInput
281288
* @expectedException \Exception
282289
*/
283290
public function testSetPaymentMethodWithoutRequiredPaymentMethodInput()
@@ -286,7 +293,9 @@ public function testSetPaymentMethodWithoutRequiredPaymentMethodInput()
286293
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId);
287294

288295
$setPaymentQuery = $this->getSetPaymentBraintreeQueryInvalidPaymentMethodInput($maskedQuoteId);
289-
$this->expectExceptionMessage("for \"braintree\" is missing.");
296+
$this->expectExceptionMessage(
297+
'Field BraintreeInput.is_active_payment_token_enabler of required type Boolean! was not provided.'
298+
);
290299
$this->graphQlMutation($setPaymentQuery, [], '', $this->getHeaderMap());
291300
}
292301

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,14 @@ public function testSetPaymentMethodInvalidMethodInput()
151151
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId);
152152

153153
$setPaymentQuery = $this->getSetPaymentBraintreeQueryInvalidMethodInput($maskedQuoteId);
154-
$this->expectExceptionMessage("for \"braintree\" is missing.");
154+
155+
$this->expectExceptionMessage(
156+
'Field BraintreeInput.is_active_payment_token_enabler of required type Boolean! was not provided'
157+
);
158+
$this->expectExceptionMessage(
159+
'Field BraintreeInput.payment_method_nonce of required type String! was not provided.'
160+
);
161+
155162
$this->graphQlMutation($setPaymentQuery);
156163
}
157164

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function testCreateCustomerAccountWithoutPassword()
114114

115115
/**
116116
* @expectedException \Exception
117-
* @expectedExceptionMessage Field CustomerInput.email of required type String! was not provided
117+
* @expectedExceptionMessage "input" value should be specified
118118
*/
119119
public function testCreateCustomerIfInputDataIsEmpty()
120120
{
@@ -140,7 +140,7 @@ public function testCreateCustomerIfInputDataIsEmpty()
140140

141141
/**
142142
* @expectedException \Exception
143-
* @expectedExceptionMessage Field CustomerInput.email of required type String! was not provided
143+
* @expectedExceptionMessage Required parameters are missing: Email
144144
*/
145145
public function testCreateCustomerIfEmailMissed()
146146
{
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GraphQl\Framework;
9+
10+
use Magento\TestFramework\TestCase\GraphQlAbstract;
11+
use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException;
12+
13+
/**
14+
* Test that required input parameters are properly validated on framework level
15+
*/
16+
class RequiredInputArgumentTest extends GraphQlAbstract
17+
{
18+
19+
/**
20+
* Test that a simple input value will be treated as required
21+
*
22+
* We should see error message from framework not the Resolver
23+
* urlResolver query has required input arg "url"
24+
*/
25+
public function testSimpleInputArgumentRequired()
26+
{
27+
$query = <<<QUERY
28+
{
29+
urlResolver{
30+
id
31+
type
32+
}
33+
}
34+
QUERY;
35+
36+
$expectedExceptionsMessage = 'GraphQL response contains errors:'
37+
. ' Field "urlResolver" argument "url" of type "String!" is required but not provided.';
38+
$this->expectException(ResponseContainsErrorsException::class);
39+
$this->expectExceptionMessage($expectedExceptionsMessage);
40+
41+
$this->graphQlQuery($query);
42+
}
43+
44+
/**
45+
* Test that a more complex required argument is handled properly
46+
*
47+
* updateCartItems mutation has required parameter input.cart_items.cart_item_id
48+
*/
49+
public function testInputObjectArgumentRequired()
50+
{
51+
$query = <<<QUERY
52+
mutation {
53+
updateCartItems(
54+
input: {
55+
cart_id: "foobar"
56+
cart_items: [
57+
{
58+
quantity: 2
59+
}
60+
]
61+
}
62+
) {
63+
cart {
64+
total_quantity
65+
}
66+
}
67+
}
68+
QUERY;
69+
70+
$expectedExceptionsMessage = 'GraphQL response contains errors:'
71+
. ' Field CartItemUpdateInput.cart_item_id of required type Int! was not provided.';
72+
$this->expectException(ResponseContainsErrorsException::class);
73+
$this->expectExceptionMessage($expectedExceptionsMessage);
74+
75+
$this->graphQlMutation($query);
76+
}
77+
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function testAddSimpleProductToCart()
8585
/**
8686
* @magentoApiDataFixture Magento/Customer/_files/customer.php
8787
* @expectedException Exception
88-
* @expectedExceptionMessage Required parameter "cart_id" is missing
88+
* @expectedExceptionMessage Field AddSimpleProductsToCartInput.cart_id of required type String! was not provided.
8989
*/
9090
public function testAddSimpleProductToCartIfCartIdIsMissed()
9191
{
@@ -138,7 +138,6 @@ public function testAddSimpleProductToCartIfCartIdIsEmpty()
138138
/**
139139
* @magentoApiDataFixture Magento/Customer/_files/customer.php
140140
* @expectedException Exception
141-
* @expectedExceptionMessage Required parameter "cart_items" is missing
142141
*/
143142
public function testAddSimpleProductToCartIfCartItemsAreMissed()
144143
{
@@ -158,6 +157,11 @@ public function testAddSimpleProductToCartIfCartItemsAreMissed()
158157
}
159158
QUERY;
160159

160+
$this->expectExceptionMessage(
161+
'Field AddSimpleProductsToCartInput.cart_items of required type'
162+
. ' [SimpleProductCartItemInput]! was not provided.'
163+
);
164+
161165
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
162166
}
163167

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function testAddVirtualProductToCart()
5757
/**
5858
* @magentoApiDataFixture Magento/Customer/_files/customer.php
5959
* @expectedException Exception
60-
* @expectedExceptionMessage Required parameter "cart_id" is missing
60+
* @expectedExceptionMessage Field AddSimpleProductsToCartInput.cart_id of required type String! was not provided.
6161
*/
6262
public function testAddVirtualProductToCartIfCartIdIsMissed()
6363
{
@@ -109,8 +109,6 @@ public function testAddVirtualProductToCartIfCartIdIsEmpty()
109109

110110
/**
111111
* @magentoApiDataFixture Magento/Customer/_files/customer.php
112-
* @expectedException Exception
113-
* @expectedExceptionMessage Required parameter "cart_items" is missing
114112
*/
115113
public function testAddVirtualProductToCartIfCartItemsAreMissed()
116114
{
@@ -129,6 +127,11 @@ public function testAddVirtualProductToCartIfCartItemsAreMissed()
129127
}
130128
}
131129
QUERY;
130+
$this->expectException(\Exception::class);
131+
$this->expectExceptionMessage(
132+
'Field AddSimpleProductsToCartInput.cart_items of required type [SimpleProductCartItemInput]!'
133+
. ' was not provided.'
134+
);
132135

133136
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
134137
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,11 @@ public function dataProviderUpdateWithMissedRequiredParameters(): array
217217
return [
218218
'missed_cart_id' => [
219219
'coupon_code: "test"',
220-
'Required parameter "cart_id" is missing'
220+
'Field ApplyCouponToCartInput.cart_id of required type String! was not provided.'
221221
],
222222
'missed_coupon_code' => [
223223
'cart_id: "test_quote"',
224-
'Required parameter "coupon_code" is missing'
224+
'Field ApplyCouponToCartInput.coupon_code of required type String! was not provided.'
225225
],
226226
];
227227
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function testPlaceOrderIfCartIdIsEmpty()
106106
/**
107107
* @magentoApiDataFixture Magento/Customer/_files/customer.php
108108
* @expectedException Exception
109-
* @expectedExceptionMessage Required parameter "cart_id" is missing
109+
* @expectedExceptionMessage Field PlaceOrderInput.cart_id of required type String! was not provided.
110110
*/
111111
public function testPlaceOrderIfCartIdIsMissed()
112112
{

0 commit comments

Comments
 (0)