Skip to content

Commit 8e40ce2

Browse files
author
Vitaliy Boyko
committed
graphQl-581: set shipping method on an empty cart test coverage
1 parent ab188bc commit 8e40ce2

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
{
@@ -261,7 +262,7 @@ public function dataProviderSetShippingMethodWithWrongParameters(): array
261262
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
262263
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
263264
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
264-
* @expectedException \Exception
265+
* @expectedException Exception
265266
* @expectedExceptionMessage You cannot specify multiple shipping methods.
266267
*/
267268
public function testSetMultipleShippingMethods()
@@ -307,7 +308,7 @@ public function testSetMultipleShippingMethods()
307308
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
308309
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
309310
*
310-
* @expectedException \Exception
311+
* @expectedException Exception
311312
*/
312313
public function testSetShippingMethodToGuestCart()
313314
{
@@ -336,7 +337,7 @@ public function testSetShippingMethodToGuestCart()
336337
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
337338
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
338339
*
339-
* @expectedException \Exception
340+
* @expectedException Exception
340341
*/
341342
public function testSetShippingMethodToAnotherCustomerCart()
342343
{
@@ -422,6 +423,30 @@ private function getQuery(
422423
QUERY;
423424
}
424425

426+
/**
427+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
428+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
429+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
430+
*
431+
* @expectedException Exception
432+
* @expectedExceptionMessage The shipping method can't be set for an empty cart. Add an item to cart and try again.
433+
*/
434+
public function testSetShippingMethodOnAnEmptyCart()
435+
{
436+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
437+
$carrierCode = 'flatrate';
438+
$methodCode = 'flatrate';
439+
$quoteAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute('test_quote');
440+
441+
$query = $this->getQuery(
442+
$maskedQuoteId,
443+
$methodCode,
444+
$carrierCode,
445+
$quoteAddressId
446+
);
447+
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
448+
}
449+
425450
/**
426451
* @param string $username
427452
* @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
{
@@ -279,7 +280,7 @@ public function dataProviderSetShippingMethodWithWrongParameters(): array
279280
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
280281
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
281282
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
282-
* @expectedException \Exception
283+
* @expectedException Exception
283284
* @expectedExceptionMessage You cannot specify multiple shipping methods.
284285
*/
285286
public function testSetMultipleShippingMethods()
@@ -325,7 +326,7 @@ public function testSetMultipleShippingMethods()
325326
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
326327
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
327328
*
328-
* @expectedException \Exception
329+
* @expectedException Exception
329330
*/
330331
public function testSetShippingMethodToCustomerCart()
331332
{
@@ -373,6 +374,30 @@ public function testSetShippingMethodIfGuestIsNotOwnerOfAddress()
373374
$this->graphQlQuery($query);
374375
}
375376

377+
/**
378+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
379+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
380+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/quote_with_address.php
381+
*
382+
* @expectedException Exception
383+
* @expectedExceptionMessage The shipping method can't be set for an empty cart. Add an item to cart and try again.
384+
*/
385+
public function testSetShippingMethodOnAnEmptyCart()
386+
{
387+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
388+
$carrierCode = 'flatrate';
389+
$methodCode = 'flatrate';
390+
$quoteAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute('test_quote');
391+
392+
$query = $this->getQuery(
393+
$maskedQuoteId,
394+
$methodCode,
395+
$carrierCode,
396+
$quoteAddressId
397+
);
398+
$this->graphQlQuery($query);
399+
}
400+
376401
/**
377402
* @param string $maskedQuoteId
378403
* @param string $shippingMethodCode

0 commit comments

Comments
 (0)