@@ -98,25 +98,87 @@ public function testAddSimpleProductWithOptions()
98
98
}
99
99
100
100
/**
101
+ * @param string $sku
102
+ * @param string $message
103
+ *
104
+ * @dataProvider wrongSkuDataProvider
105
+ *
101
106
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
102
- * @group wip
103
107
*/
104
- public function testAddProductWithWrongSku ()
108
+ public function testAddProductWithWrongSku (string $ sku , string $ message )
105
109
{
106
110
$ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_order_1 ' );
107
- $ sku = 'non-existent ' ;
108
111
109
112
$ query = $ this ->getQuery ($ maskedQuoteId , 1 , $ sku , '' );
110
113
$ response = $ this ->graphQlMutation ($ query );
111
114
112
115
self ::assertArrayHasKey ('userInputErrors ' , $ response ['addProductsToCart ' ]);
113
116
self ::assertCount (1 , $ response ['addProductsToCart ' ]['userInputErrors ' ]);
114
117
self ::assertEquals (
115
- 'Could not find a product with SKU " ' . $ sku .'" ' ,
118
+ $ message ,
119
+ $ response ['addProductsToCart ' ]['userInputErrors ' ][0 ]['message ' ]
120
+ );
121
+ }
122
+
123
+ /**
124
+ * @param int $quantity
125
+ * @param string $message
126
+ *
127
+ * @dataProvider wrongQuantityDataProvider
128
+ *
129
+ * @magentoApiDataFixture Magento/Catalog/_files/product_simple_without_custom_options.php
130
+ * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
131
+ */
132
+ public function testAddProductWithWrongQuantity (int $ quantity , string $ message )
133
+ {
134
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_order_1 ' );
135
+ $ sku = 'simple-2 ' ;
136
+
137
+ $ query = $ this ->getQuery ($ maskedQuoteId , $ quantity , $ sku , '' );
138
+ $ response = $ this ->graphQlMutation ($ query );
139
+ self ::assertArrayHasKey ('userInputErrors ' , $ response ['addProductsToCart ' ]);
140
+ self ::assertCount (1 , $ response ['addProductsToCart ' ]['userInputErrors ' ]);
141
+
142
+ self ::assertEquals (
143
+ $ message ,
116
144
$ response ['addProductsToCart ' ]['userInputErrors ' ][0 ]['message ' ]
117
145
);
118
146
}
119
147
148
+ /**
149
+ * @return array
150
+ */
151
+ public function wrongSkuDataProvider (): array
152
+ {
153
+ return [
154
+ 'Non-existent SKU ' => [
155
+ 'non-existent ' ,
156
+ 'Could not find a product with SKU "non-existent" '
157
+ ],
158
+ 'Empty SKU ' => [
159
+ '' ,
160
+ 'Could not find a product with SKU "" '
161
+ ]
162
+ ];
163
+ }
164
+
165
+ /**
166
+ * @return array
167
+ */
168
+ public function wrongQuantityDataProvider (): array
169
+ {
170
+ return [
171
+ 'More quantity than in stock ' => [
172
+ 101 ,
173
+ 'The requested qty is not available '
174
+ ],
175
+ 'Quantity equals zero ' => [
176
+ 0 ,
177
+ 'The product quantity should be greater than 0 '
178
+ ]
179
+ ];
180
+ }
181
+
120
182
/**
121
183
* Returns GraphQl query string
122
184
*
0 commit comments