Skip to content

Commit 2c00485

Browse files
ENGCOM-5220: #681: [Test coverage] missed or empty 'cart_id' in cart operations #711
- Merge Pull Request magento/graphql-ce#711 from sergiy-v/graphql-ce:681-missed-cart-id-in-cart-operations - Merged commits: 1. a7bdee7
2 parents b81986b + a7bdee7 commit 2c00485

10 files changed

+640
-20
lines changed

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

Lines changed: 109 additions & 2 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\Framework\Exception\AuthenticationException;
1112
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
1213
use Magento\Integration\Api\CustomerTokenServiceInterface;
@@ -53,11 +54,117 @@ public function testAddSimpleProductToCart()
5354
self::assertEquals($sku, $response['addSimpleProductsToCart']['cart']['items'][0]['product']['sku']);
5455
}
5556

57+
/**
58+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
59+
* @expectedException Exception
60+
* @expectedExceptionMessage Required parameter "cart_id" is missing
61+
*/
62+
public function testAddSimpleProductToCartIfCartIdIsMissed()
63+
{
64+
$query = <<<QUERY
65+
mutation {
66+
addSimpleProductsToCart(
67+
input: {
68+
cart_items: []
69+
}
70+
) {
71+
cart {
72+
items {
73+
id
74+
}
75+
}
76+
}
77+
}
78+
QUERY;
79+
80+
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
81+
}
82+
83+
/**
84+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
85+
* @expectedException Exception
86+
* @expectedExceptionMessage Required parameter "cart_id" is missing
87+
*/
88+
public function testAddSimpleProductToCartIfCartIdIsEmpty()
89+
{
90+
$query = <<<QUERY
91+
mutation {
92+
addSimpleProductsToCart(
93+
input: {
94+
cart_id: "",
95+
cart_items: []
96+
}
97+
) {
98+
cart {
99+
items {
100+
id
101+
}
102+
}
103+
}
104+
}
105+
QUERY;
106+
107+
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
108+
}
109+
110+
/**
111+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
112+
* @expectedException Exception
113+
* @expectedExceptionMessage Required parameter "cart_items" is missing
114+
*/
115+
public function testAddSimpleProductToCartIfCartItemsAreMissed()
116+
{
117+
$query = <<<QUERY
118+
mutation {
119+
addSimpleProductsToCart(
120+
input: {
121+
cart_id: "cart_id"
122+
}
123+
) {
124+
cart {
125+
items {
126+
id
127+
}
128+
}
129+
}
130+
}
131+
QUERY;
132+
133+
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
134+
}
135+
136+
/**
137+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
138+
* @expectedException Exception
139+
* @expectedExceptionMessage Required parameter "cart_items" is missing
140+
*/
141+
public function testAddSimpleProductToCartIfCartItemsAreEmpty()
142+
{
143+
$query = <<<QUERY
144+
mutation {
145+
addSimpleProductsToCart(
146+
input: {
147+
cart_id: "cart_id",
148+
cart_items: []
149+
}
150+
) {
151+
cart {
152+
items {
153+
id
154+
}
155+
}
156+
}
157+
}
158+
QUERY;
159+
160+
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
161+
}
162+
56163
/**
57164
* @magentoApiDataFixture Magento/Customer/_files/customer.php
58165
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
59166
*
60-
* @expectedException \Exception
167+
* @expectedException Exception
61168
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
62169
*/
63170
public function testAddProductToNonExistentCart()
@@ -74,7 +181,7 @@ public function testAddProductToNonExistentCart()
74181
* @magentoApiDataFixture Magento/Customer/_files/customer.php
75182
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
76183
*
77-
* @expectedException \Exception
184+
* @expectedException Exception
78185
* @expectedExceptionMessage Could not find a product with SKU "simple_product"
79186
*/
80187
public function testNonExistentProductToCart()

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

Lines changed: 109 additions & 2 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\Framework\Exception\AuthenticationException;
1112
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
1213
use Magento\Integration\Api\CustomerTokenServiceInterface;
@@ -53,11 +54,117 @@ public function testAddVirtualProductToCart()
5354
self::assertEquals($sku, $response['addVirtualProductsToCart']['cart']['items'][0]['product']['sku']);
5455
}
5556

57+
/**
58+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
59+
* @expectedException Exception
60+
* @expectedExceptionMessage Required parameter "cart_id" is missing
61+
*/
62+
public function testAddVirtualProductToCartIfCartIdIsMissed()
63+
{
64+
$query = <<<QUERY
65+
mutation {
66+
addSimpleProductsToCart(
67+
input: {
68+
cart_items: []
69+
}
70+
) {
71+
cart {
72+
items {
73+
id
74+
}
75+
}
76+
}
77+
}
78+
QUERY;
79+
80+
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
81+
}
82+
83+
/**
84+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
85+
* @expectedException Exception
86+
* @expectedExceptionMessage Required parameter "cart_id" is missing
87+
*/
88+
public function testAddVirtualProductToCartIfCartIdIsEmpty()
89+
{
90+
$query = <<<QUERY
91+
mutation {
92+
addSimpleProductsToCart(
93+
input: {
94+
cart_id: "",
95+
cart_items: []
96+
}
97+
) {
98+
cart {
99+
items {
100+
id
101+
}
102+
}
103+
}
104+
}
105+
QUERY;
106+
107+
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
108+
}
109+
110+
/**
111+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
112+
* @expectedException Exception
113+
* @expectedExceptionMessage Required parameter "cart_items" is missing
114+
*/
115+
public function testAddVirtualProductToCartIfCartItemsAreMissed()
116+
{
117+
$query = <<<QUERY
118+
mutation {
119+
addSimpleProductsToCart(
120+
input: {
121+
cart_id: "cart_id"
122+
}
123+
) {
124+
cart {
125+
items {
126+
id
127+
}
128+
}
129+
}
130+
}
131+
QUERY;
132+
133+
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
134+
}
135+
136+
/**
137+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
138+
* @expectedException Exception
139+
* @expectedExceptionMessage Required parameter "cart_items" is missing
140+
*/
141+
public function testAddVirtualProductToCartIfCartItemsAreEmpty()
142+
{
143+
$query = <<<QUERY
144+
mutation {
145+
addSimpleProductsToCart(
146+
input: {
147+
cart_id: "cart_id",
148+
cart_items: []
149+
}
150+
) {
151+
cart {
152+
items {
153+
id
154+
}
155+
}
156+
}
157+
}
158+
QUERY;
159+
160+
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
161+
}
162+
56163
/**
57164
* @magentoApiDataFixture Magento/Customer/_files/customer.php
58165
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/virtual_product.php
59166
*
60-
* @expectedException \Exception
167+
* @expectedException Exception
61168
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
62169
*/
63170
public function testAddVirtualToNonExistentCart()
@@ -74,7 +181,7 @@ public function testAddVirtualToNonExistentCart()
74181
* @magentoApiDataFixture Magento/Customer/_files/customer.php
75182
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
76183
*
77-
* @expectedException \Exception
184+
* @expectedException Exception
78185
* @expectedExceptionMessage Could not find a product with SKU "virtual_product"
79186
*/
80187
public function testNonExistentProductToCart()

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

Lines changed: 36 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\Integration\Api\CustomerTokenServiceInterface;
1213
use Magento\TestFramework\Helper\Bootstrap;
@@ -94,10 +95,41 @@ public function testGetAnotherCustomerCart()
9495
$this->graphQlQuery($query, [], '', $this->getHeaderMap('customer2@search.example.com'));
9596
}
9697

98+
/**
99+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
100+
* @expectedException Exception
101+
* @expectedExceptionMessage Required parameter "cart_id" is missing
102+
*/
103+
public function testGetCartIfCartIdIsEmpty()
104+
{
105+
$maskedQuoteId = '';
106+
$query = $this->getQuery($maskedQuoteId);
107+
108+
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
109+
}
110+
111+
/**
112+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
113+
* @expectedException Exception
114+
* @expectedExceptionMessage Field "cart" argument "cart_id" of type "String!" is required but not provided.
115+
*/
116+
public function testGetCartIfCartIdIsMissed()
117+
{
118+
$query = <<<QUERY
119+
{
120+
cart {
121+
email
122+
}
123+
}
124+
QUERY;
125+
126+
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
127+
}
128+
97129
/**
98130
* @magentoApiDataFixture Magento/Customer/_files/customer.php
99131
*
100-
* @expectedException \Exception
132+
* @expectedException Exception
101133
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
102134
*/
103135
public function testGetNonExistentCart()
@@ -113,7 +145,7 @@ public function testGetNonExistentCart()
113145
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
114146
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/make_cart_inactive.php
115147
*
116-
* @expectedException \Exception
148+
* @expectedException Exception
117149
* @expectedExceptionMessage Current user does not have an active cart.
118150
*/
119151
public function testGetInactiveCart()
@@ -145,7 +177,7 @@ public function testGetCartWithNotDefaultStore()
145177
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
146178
* @magentoApiDataFixture Magento/Store/_files/second_store.php
147179
*
148-
* @expectedException \Exception
180+
* @expectedException Exception
149181
* @expectedExceptionMessage Wrong store code specified for cart
150182
*/
151183
public function testGetCartWithWrongStore()
@@ -162,7 +194,7 @@ public function testGetCartWithWrongStore()
162194
/**
163195
* @magentoApiDataFixture Magento/Checkout/_files/active_quote_customer_not_default_store.php
164196
*
165-
* @expectedException \Exception
197+
* @expectedException Exception
166198
* @expectedExceptionMessage Requested store is not found
167199
*/
168200
public function testGetCartWithNotExistingStore()

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

Lines changed: 34 additions & 0 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\Framework\Registry;
1112
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
1213
use Magento\Integration\Api\CustomerTokenServiceInterface;
@@ -83,6 +84,39 @@ public function testPlaceOrder()
8384
self::assertEquals($reservedOrderId, $response['placeOrder']['order']['order_id']);
8485
}
8586

87+
/**
88+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
89+
* @expectedException Exception
90+
* @expectedExceptionMessage Required parameter "cart_id" is missing
91+
*/
92+
public function testPlaceOrderIfCartIdIsEmpty()
93+
{
94+
$maskedQuoteId = '';
95+
$query = $this->getQuery($maskedQuoteId);
96+
97+
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
98+
}
99+
100+
/**
101+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
102+
* @expectedException Exception
103+
* @expectedExceptionMessage Required parameter "cart_id" is missing
104+
*/
105+
public function testPlaceOrderIfCartIdIsMissed()
106+
{
107+
$query = <<<QUERY
108+
mutation {
109+
placeOrder(input: {}) {
110+
order {
111+
order_id
112+
}
113+
}
114+
}
115+
QUERY;
116+
117+
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
118+
}
119+
86120
/**
87121
* @magentoApiDataFixture Magento/Customer/_files/customer.php
88122
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php

0 commit comments

Comments
 (0)