Skip to content

Commit 0d881fc

Browse files
authored
Merge pull request #3945 from magento-engcom/graphql-develop-prs
[EngCom] Public Pull Requests - GraphQL
2 parents 9d6d4e2 + 05c9b49 commit 0d881fc

File tree

14 files changed

+445
-8
lines changed

14 files changed

+445
-8
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ type Query {
1010
type Currency {
1111
base_currency_code: String
1212
base_currency_symbol: String
13-
default_display_currecy_code: String
14-
default_display_currecy_symbol: String
13+
default_display_currecy_code: String @deprecated(reason: "Symbol was missed. Use `default_display_currency_code`.")
14+
default_display_currency_code: String
15+
default_display_currecy_symbol: String @deprecated(reason: "Symbol was missed. Use `default_display_currency_symbol`.")
16+
default_display_currency_symbol: String
1517
available_currency_codes: [String]
1618
exchange_rates: [ExchangeRate]
1719
}

app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ public function execute(Quote $cart, array $cartItemData): void
6767
{
6868
$sku = $this->extractSku($cartItemData);
6969
$qty = $this->extractQty($cartItemData);
70+
if ($qty <= 0) {
71+
throw new GraphQlInputException(
72+
__('Please enter a number greater than 0 in this field.')
73+
);
74+
}
7075
$customizableOptions = $this->extractCustomizableOptions($cartItemData);
7176

7277
try {

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

app/code/Magento/WishlistGraphQl/Model/Resolver/WishlistResolver.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Wishlist\Model\ResourceModel\Wishlist as WishlistResourceModel;
1414
use Magento\Wishlist\Model\Wishlist;
1515
use Magento\Wishlist\Model\WishlistFactory;
16+
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
1617

1718
/**
1819
* Fetches the Wishlist data according to the GraphQL schema
@@ -51,6 +52,10 @@ public function resolve(
5152
) {
5253
$customerId = $context->getUserId();
5354

55+
/* Guest checking */
56+
if (!$customerId && 0 === $customerId) {
57+
throw new GraphQlAuthorizationException(__('The current user cannot perform operations on wishlist'));
58+
}
5459
/** @var Wishlist $wishlist */
5560
$wishlist = $this->wishlistFactory->create();
5661
$this->wishlistResource->load($wishlist, $customerId, 'customer_id');

dev/tests/api-functional/testsuite/Magento/GraphQl/Directory/CurrencyTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public function testGetCurrency()
2121
currency {
2222
base_currency_code
2323
base_currency_symbol
24-
default_display_currecy_code
25-
default_display_currecy_symbol
24+
default_display_currency_code
25+
default_display_currency_symbol
2626
available_currency_codes
2727
exchange_rates {
2828
currency_to
@@ -36,8 +36,8 @@ public function testGetCurrency()
3636
$this->assertArrayHasKey('currency', $result);
3737
$this->assertArrayHasKey('base_currency_code', $result['currency']);
3838
$this->assertArrayHasKey('base_currency_symbol', $result['currency']);
39-
$this->assertArrayHasKey('default_display_currecy_code', $result['currency']);
40-
$this->assertArrayHasKey('default_display_currecy_symbol', $result['currency']);
39+
$this->assertArrayHasKey('default_display_currency_code', $result['currency']);
40+
$this->assertArrayHasKey('default_display_currency_symbol', $result['currency']);
4141
$this->assertArrayHasKey('available_currency_codes', $result['currency']);
4242
$this->assertArrayHasKey('exchange_rates', $result['currency']);
4343
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,22 @@ public function testAddSimpleProductToCart()
5959
self::assertEquals($sku, $response['addSimpleProductsToCart']['cart']['items'][0]['product']['sku']);
6060
}
6161

62+
/**
63+
* @magentoApiDataFixture Magento/Catalog/_files/products.php
64+
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
65+
* @expectedException \Exception
66+
* @expectedExceptionMessage Please enter a number greater than 0 in this field.
67+
*/
68+
public function testAddSimpleProductToCartWithNegativeQty()
69+
{
70+
$sku = 'simple';
71+
$qty = -2;
72+
$maskedQuoteId = $this->getMaskedQuoteId();
73+
74+
$query = $this->getAddSimpleProductQuery($maskedQuoteId, $sku, $qty);
75+
$this->graphQlQuery($query);
76+
}
77+
6278
/**
6379
* @return string
6480
*/

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,39 @@ public function testSetBillingAddressOnNonExistentCart()
423423
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
424424
}
425425

426+
/**
427+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
428+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
429+
* @dataProvider dataProviderSetWithoutRequiredParameters
430+
* @param string $input
431+
* @param string $message
432+
* @throws \Exception
433+
*/
434+
public function testSetBillingAddressWithoutRequiredParameters(string $input, string $message)
435+
{
436+
$maskedQuoteId = $this->assignQuoteToCustomer();
437+
$input = str_replace('cart_id_value', $maskedQuoteId, $input);
438+
439+
$query = <<<QUERY
440+
mutation {
441+
setBillingAddressOnCart(
442+
input: {
443+
{$input}
444+
}
445+
) {
446+
cart {
447+
billing_address {
448+
city
449+
}
450+
}
451+
}
452+
}
453+
QUERY;
454+
455+
$this->expectExceptionMessage($message);
456+
$this->graphQlQuery($query);
457+
}
458+
426459
/**
427460
* Verify the all the whitelisted fields for a New Address Object
428461
*
@@ -506,4 +539,22 @@ private function assignQuoteToCustomer(
506539
$this->quoteResource->save($quote);
507540
return $this->quoteIdToMaskedId->execute((int)$quote->getId());
508541
}
542+
543+
/**
544+
* @return array
545+
*/
546+
public function dataProviderSetWithoutRequiredParameters()
547+
{
548+
return [
549+
'missed_billing_address' => [
550+
'cart_id: "cart_id_value"',
551+
'Field SetBillingAddressOnCartInput.billing_address of required type BillingAddressInput!'
552+
. ' was not provided.',
553+
],
554+
'missed_cart_id' => [
555+
'billing_address: {}',
556+
'Required parameter "cart_id" is missing'
557+
]
558+
];
559+
}
509560
}

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/SetBillingAddressOnCartTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,38 @@ public function testSetBillingAddressOnNonExistentCart()
263263
$this->graphQlQuery($query);
264264
}
265265

266+
/**
267+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
268+
* @dataProvider dataProviderSetWithoutRequiredParameters
269+
* @param string $input
270+
* @param string $message
271+
* @throws \Exception
272+
*/
273+
public function testSetBillingAddressWithoutRequiredParameters(string $input, string $message)
274+
{
275+
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address');
276+
$input = str_replace('cart_id_value', $maskedQuoteId, $input);
277+
278+
$query = <<<QUERY
279+
mutation {
280+
setBillingAddressOnCart(
281+
input: {
282+
{$input}
283+
}
284+
) {
285+
cart {
286+
billing_address {
287+
city
288+
}
289+
}
290+
}
291+
}
292+
QUERY;
293+
294+
$this->expectExceptionMessage($message);
295+
$this->graphQlQuery($query);
296+
}
297+
266298
/**
267299
* Verify the all the whitelisted fields for a New Address Object
268300
*
@@ -297,4 +329,22 @@ private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): str
297329

298330
return $this->quoteIdToMaskedId->execute((int)$quote->getId());
299331
}
332+
333+
/**
334+
* @return array
335+
*/
336+
public function dataProviderSetWithoutRequiredParameters()
337+
{
338+
return [
339+
'missed_billing_address' => [
340+
'cart_id: "cart_id_value"',
341+
'Field SetBillingAddressOnCartInput.billing_address of required type BillingAddressInput!'
342+
. ' was not provided.',
343+
],
344+
'missed_cart_id' => [
345+
'billing_address: {}',
346+
'Required parameter "cart_id" is missing'
347+
]
348+
];
349+
}
300350
}

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)