Skip to content

Commit 9ae2264

Browse files
authored
ENGCOM-4727: graphQl-581: set shipping method on an empty cart test coverage #586
2 parents 1791b43 + 3d10fcc commit 9ae2264

File tree

2 files changed

+58
-8
lines changed

2 files changed

+58
-8
lines changed

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

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\GraphQl\Quote\Customer;
99

10+
use Exception;
1011
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
1112
use Magento\GraphQl\Quote\GetQuoteShippingAddressIdByReservedQuoteId;
1213
use Magento\Integration\Api\CustomerTokenServiceInterface;
@@ -132,7 +133,7 @@ public function testReSetShippingMethod()
132133
* @param string $input
133134
* @param string $message
134135
* @dataProvider dataProviderSetShippingMethodWithWrongParameters
135-
* @throws \Exception
136+
* @throws Exception
136137
*/
137138
public function testSetShippingMethodWithWrongParameters(string $input, string $message)
138139
{
@@ -269,7 +270,7 @@ public function dataProviderSetShippingMethodWithWrongParameters(): array
269270
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
270271
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
271272
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
272-
* @expectedException \Exception
273+
* @expectedException Exception
273274
* @expectedExceptionMessage You cannot specify multiple shipping methods.
274275
*/
275276
public function testSetMultipleShippingMethods()
@@ -315,7 +316,7 @@ public function testSetMultipleShippingMethods()
315316
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
316317
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
317318
*
318-
* @expectedException \Exception
319+
* @expectedException Exception
319320
*/
320321
public function testSetShippingMethodToGuestCart()
321322
{
@@ -344,7 +345,7 @@ public function testSetShippingMethodToGuestCart()
344345
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
345346
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
346347
*
347-
* @expectedException \Exception
348+
* @expectedException Exception
348349
*/
349350
public function testSetShippingMethodToAnotherCustomerCart()
350351
{
@@ -430,6 +431,30 @@ private function getQuery(
430431
QUERY;
431432
}
432433

434+
/**
435+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
436+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
437+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
438+
*
439+
* @expectedException Exception
440+
* @expectedExceptionMessage The shipping method can't be set for an empty cart. Add an item to cart and try again.
441+
*/
442+
public function testSetShippingMethodOnAnEmptyCart()
443+
{
444+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
445+
$carrierCode = 'flatrate';
446+
$methodCode = 'flatrate';
447+
$quoteAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute('test_quote');
448+
449+
$query = $this->getQuery(
450+
$maskedQuoteId,
451+
$methodCode,
452+
$carrierCode,
453+
$quoteAddressId
454+
);
455+
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
456+
}
457+
433458
/**
434459
* @param string $username
435460
* @param string $password

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

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\GraphQl\Quote\Guest;
99

10+
use Exception;
1011
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
1112
use Magento\GraphQl\Quote\GetQuoteShippingAddressIdByReservedQuoteId;
1213
use Magento\TestFramework\Helper\Bootstrap;
@@ -85,7 +86,7 @@ public function testSetShippingMethodOnCartWithSimpleProduct()
8586
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
8687
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_virtual_product.php
8788
*
88-
* @expectedException \Exception
89+
* @expectedException Exception
8990
* @expectedExceptionMessage The shipping address is missing. Set the address and try again.
9091
*/
9192
public function testSetShippingMethodOnCartWithSimpleProductAndWithoutAddress()
@@ -151,7 +152,7 @@ public function testReSetShippingMethod()
151152
* @param string $input
152153
* @param string $message
153154
* @dataProvider dataProviderSetShippingMethodWithWrongParameters
154-
* @throws \Exception
155+
* @throws Exception
155156
*/
156157
public function testSetShippingMethodWithWrongParameters(string $input, string $message)
157158
{
@@ -287,7 +288,7 @@ public function dataProviderSetShippingMethodWithWrongParameters(): array
287288
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
288289
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
289290
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
290-
* @expectedException \Exception
291+
* @expectedException Exception
291292
* @expectedExceptionMessage You cannot specify multiple shipping methods.
292293
*/
293294
public function testSetMultipleShippingMethods()
@@ -333,7 +334,7 @@ public function testSetMultipleShippingMethods()
333334
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
334335
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
335336
*
336-
* @expectedException \Exception
337+
* @expectedException Exception
337338
*/
338339
public function testSetShippingMethodToCustomerCart()
339340
{
@@ -381,6 +382,30 @@ public function testSetShippingMethodIfGuestIsNotOwnerOfAddress()
381382
$this->graphQlQuery($query);
382383
}
383384

385+
/**
386+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
387+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
388+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/quote_with_address.php
389+
*
390+
* @expectedException Exception
391+
* @expectedExceptionMessage The shipping method can't be set for an empty cart. Add an item to cart and try again.
392+
*/
393+
public function testSetShippingMethodOnAnEmptyCart()
394+
{
395+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
396+
$carrierCode = 'flatrate';
397+
$methodCode = 'flatrate';
398+
$quoteAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute('test_quote');
399+
400+
$query = $this->getQuery(
401+
$maskedQuoteId,
402+
$methodCode,
403+
$carrierCode,
404+
$quoteAddressId
405+
);
406+
$this->graphQlQuery($query);
407+
}
408+
384409
/**
385410
* @param string $maskedQuoteId
386411
* @param string $shippingMethodCode

0 commit comments

Comments
 (0)