24
24
use Magento \Quote \Test \Fixture \CustomerCart ;
25
25
use Magento \Quote \Test \Fixture \GuestCart as GuestCartFixture ;
26
26
use Magento \Quote \Test \Fixture \QuoteIdMask ;
27
+ use Magento \QuoteGraphQl \Model \ErrorMapper ;
27
28
use Magento \Sales \Api \OrderRepositoryInterface ;
28
29
use Magento \Sales \Model \OrderFactory ;
29
30
use Magento \Sales \Model \ResourceModel \Order \CollectionFactory ;
30
31
use Magento \TestFramework \Fixture \Config ;
31
32
use Magento \TestFramework \Fixture \DataFixture ;
32
33
use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
33
34
use Magento \TestFramework \Helper \Bootstrap ;
35
+ use Magento \TestFramework \TestCase \GraphQl \ResponseContainsErrorsException ;
34
36
use Magento \TestFramework \TestCase \GraphQlAbstract ;
35
37
36
38
/**
@@ -151,7 +153,6 @@ public function testPlaceOrderWithAutoGroup()
151
153
self ::assertArrayHasKey ('number ' , $ response ['placeOrder ' ]['orderV2 ' ]);
152
154
self ::assertEquals ($ reservedOrderId , $ response ['placeOrder ' ]['order ' ]['order_number ' ]);
153
155
self ::assertEquals ($ reservedOrderId , $ response ['placeOrder ' ]['orderV2 ' ]['number ' ]);
154
- self ::assertEmpty (count ($ response ['placeOrder ' ]['errors ' ]));
155
156
$ orderIncrementId = $ response ['placeOrder ' ]['order ' ]['order_number ' ];
156
157
$ order = $ this ->orderFactory ->create ();
157
158
$ order ->loadByIncrementId ($ orderIncrementId );
@@ -196,13 +197,20 @@ public function testPlaceOrderWithNoEmail()
196
197
$ maskedQuoteId = $ this ->quoteIdToMaskedQuoteIdInterface ->execute ((int ) $ cart ->getId ());
197
198
$ query = $ this ->getQuery ($ maskedQuoteId );
198
199
199
- $ response = $ this ->graphQlMutation ($ query );
200
- self ::assertEquals (1 , count ($ response ['placeOrder ' ]['errors ' ]));
201
- self ::assertEquals ('GUEST_EMAIL_MISSING ' , $ response ['placeOrder ' ]['errors ' ][0 ]['code ' ]);
202
- self ::assertEquals (
203
- 'Guest email for cart is missing. ' ,
204
- $ response ['placeOrder ' ]['errors ' ][0 ]['message ' ]
205
- );
200
+ try {
201
+ $ this ->graphQlMutation ($ query );
202
+ } catch (ResponseContainsErrorsException $ exception ) {
203
+ $ exceptionData = $ exception ->getResponseData ();
204
+ self ::assertEquals (1 , count ($ exceptionData ['errors ' ]));
205
+ self ::assertEquals (
206
+ 'Guest email for cart is missing. ' ,
207
+ $ exceptionData ['errors ' ][0 ]['message ' ]
208
+ );
209
+ self ::assertEquals (
210
+ ErrorMapper::ERROR_GUEST_EMAIL_MISSING ,
211
+ $ exceptionData ['errors ' ][0 ]['extensions ' ]['error_code ' ]
212
+ );
213
+ }
206
214
}
207
215
208
216
#[
@@ -214,13 +222,21 @@ public function testPlaceOrderWithNoItemsInCart()
214
222
$ cart = DataFixtureStorageManager::getStorage ()->get ('cart ' );
215
223
$ maskedQuoteId = $ this ->quoteIdToMaskedQuoteIdInterface ->execute ((int ) $ cart ->getId ());
216
224
$ query = $ this ->getQuery ($ maskedQuoteId );
217
- $ response = $ this ->graphQlMutation ($ query );
218
- self ::assertEquals (1 , count ($ response ['placeOrder ' ]['errors ' ]));
219
- self ::assertEquals ('UNABLE_TO_PLACE_ORDER ' , $ response ['placeOrder ' ]['errors ' ][0 ]['code ' ]);
220
- self ::assertEquals (
221
- 'A server error stopped your order from being placed. Please try to place your order again. ' ,
222
- $ response ['placeOrder ' ]['errors ' ][0 ]['message ' ]
223
- );
225
+ try {
226
+ $ this ->graphQlMutation ($ query );
227
+ } catch (ResponseContainsErrorsException $ exception ) {
228
+ $ exceptionData = $ exception ->getResponseData ();
229
+ self ::assertEquals (1 , count ($ exceptionData ['errors ' ]));
230
+ self ::assertEquals (
231
+ 'Unable to place order: A server error stopped your order from being placed. ' .
232
+ ' Please try to place your order again ' ,
233
+ $ exceptionData ['errors ' ][0 ]['message ' ]
234
+ );
235
+ self ::assertEquals (
236
+ ErrorMapper::ERROR_UNABLE_TO_PLACE_ORDER ,
237
+ $ exceptionData ['errors ' ][0 ]['extensions ' ]['error_code ' ]
238
+ );
239
+ }
224
240
}
225
241
226
242
#[
@@ -235,13 +251,21 @@ public function testPlaceOrderWithNoShippingAddress()
235
251
$ cart = DataFixtureStorageManager::getStorage ()->get ('cart ' );
236
252
$ maskedQuoteId = $ this ->quoteIdToMaskedQuoteIdInterface ->execute ((int ) $ cart ->getId ());
237
253
$ query = $ this ->getQuery ($ maskedQuoteId );
238
- $ response = $ this ->graphQlMutation ($ query );
239
- self ::assertEquals (1 , count ($ response ['placeOrder ' ]['errors ' ]));
240
- self ::assertEquals ('UNABLE_TO_PLACE_ORDER ' , $ response ['placeOrder ' ]['errors ' ][0 ]['code ' ]);
241
- self ::assertEquals (
242
- 'Some addresses can \'t be used due to the configurations for specific countries. ' ,
243
- $ response ['placeOrder ' ]['errors ' ][0 ]['message ' ]
244
- );
254
+ try {
255
+ $ this ->graphQlMutation ($ query );
256
+ } catch (ResponseContainsErrorsException $ exception ) {
257
+ $ exceptionData = $ exception ->getResponseData ();
258
+ self ::assertEquals (1 , count ($ exceptionData ['errors ' ]));
259
+ self ::assertEquals (
260
+ 'Unable to place order: Some addresses can \'t be used due to the ' .
261
+ ' configurations for specific countries. ' ,
262
+ $ exceptionData ['errors ' ][0 ]['message ' ]
263
+ );
264
+ self ::assertEquals (
265
+ ErrorMapper::ERROR_UNABLE_TO_PLACE_ORDER ,
266
+ $ exceptionData ['errors ' ][0 ]['extensions ' ]['error_code ' ]
267
+ );
268
+ }
245
269
}
246
270
247
271
#[
@@ -257,13 +281,20 @@ public function testPlaceOrderWithNoShippingMethod()
257
281
$ cart = DataFixtureStorageManager::getStorage ()->get ('cart ' );
258
282
$ maskedQuoteId = $ this ->quoteIdToMaskedQuoteIdInterface ->execute ((int ) $ cart ->getId ());
259
283
$ query = $ this ->getQuery ($ maskedQuoteId );
260
- $ response = $ this ->graphQlMutation ($ query );
261
- self ::assertEquals (1 , count ($ response ['placeOrder ' ]['errors ' ]));
262
- self ::assertEquals ('UNABLE_TO_PLACE_ORDER ' , $ response ['placeOrder ' ]['errors ' ][0 ]['code ' ]);
263
- self ::assertEquals (
264
- 'The shipping method is missing. Select the shipping method and try again. ' ,
265
- $ response ['placeOrder ' ]['errors ' ][0 ]['message ' ]
266
- );
284
+ try {
285
+ $ this ->graphQlMutation ($ query );
286
+ } catch (ResponseContainsErrorsException $ exception ) {
287
+ $ exceptionData = $ exception ->getResponseData ();
288
+ self ::assertEquals (1 , count ($ exceptionData ['errors ' ]));
289
+ self ::assertEquals (
290
+ 'Unable to place order: The shipping method is missing. Select the shipping method and try again. ' ,
291
+ $ exceptionData ['errors ' ][0 ]['message ' ]
292
+ );
293
+ self ::assertEquals (
294
+ ErrorMapper::ERROR_UNABLE_TO_PLACE_ORDER ,
295
+ $ exceptionData ['errors ' ][0 ]['extensions ' ]['error_code ' ]
296
+ );
297
+ }
267
298
}
268
299
269
300
#[
@@ -284,13 +315,24 @@ public function testPlaceOrderWithNoBillingAddress()
284
315
$ maskedQuoteId = $ this ->quoteIdToMaskedQuoteIdInterface ->execute ((int ) $ cart ->getId ());
285
316
$ query = $ this ->getQuery ($ maskedQuoteId );
286
317
287
- $ response = $ this ->graphQlMutation ($ query );
288
- self ::assertEquals (1 , count ($ response ['placeOrder ' ]['errors ' ]));
289
- self ::assertEquals ('UNABLE_TO_PLACE_ORDER ' , $ response ['placeOrder ' ]['errors ' ][0 ]['code ' ]);
290
- self ::assertStringContainsString (
291
- 'Please check the billing address information. ' ,
292
- $ response ['placeOrder ' ]['errors ' ][0 ]['message ' ]
293
- );
318
+ try {
319
+ $ this ->graphQlMutation ($ query );
320
+ } catch (ResponseContainsErrorsException $ exception ) {
321
+ $ exceptionData = $ exception ->getResponseData ();
322
+ self ::assertEquals (1 , count ($ exceptionData ['errors ' ]));
323
+ self ::assertEquals (
324
+ 'Unable to place order: Please check the billing address information. ' .
325
+ '"firstname" is required. Enter and try again. "lastname" is required. Enter and try again. ' .
326
+ '"street" is required. Enter and try again. "city" is required. Enter and try again. ' .
327
+ '"telephone" is required. Enter and try again. "postcode" is required. Enter and try again. ' .
328
+ '"countryId" is required. Enter and try again. ' ,
329
+ $ exceptionData ['errors ' ][0 ]['message ' ]
330
+ );
331
+ self ::assertEquals (
332
+ ErrorMapper::ERROR_UNABLE_TO_PLACE_ORDER ,
333
+ $ exceptionData ['errors ' ][0 ]['extensions ' ]['error_code ' ]
334
+ );
335
+ }
294
336
}
295
337
296
338
#[
@@ -311,13 +353,20 @@ public function testPlaceOrderWithNoPaymentMethod()
311
353
$ cart = DataFixtureStorageManager::getStorage ()->get ('cart ' );
312
354
$ maskedQuoteId = $ this ->quoteIdToMaskedQuoteIdInterface ->execute ((int ) $ cart ->getId ());
313
355
$ query = $ this ->getQuery ($ maskedQuoteId );
314
- $ response = $ this ->graphQlMutation ($ query );
315
- self ::assertEquals (1 , count ($ response ['placeOrder ' ]['errors ' ]));
316
- self ::assertEquals ('UNABLE_TO_PLACE_ORDER ' , $ response ['placeOrder ' ]['errors ' ][0 ]['code ' ]);
317
- self ::assertEquals (
318
- 'Enter a valid payment method and try again. ' ,
319
- $ response ['placeOrder ' ]['errors ' ][0 ]['message ' ]
320
- );
356
+ try {
357
+ $ this ->graphQlMutation ($ query );
358
+ } catch (ResponseContainsErrorsException $ exception ) {
359
+ $ exceptionData = $ exception ->getResponseData ();
360
+ self ::assertEquals (1 , count ($ exceptionData ['errors ' ]));
361
+ self ::assertEquals (
362
+ 'Unable to place order: Enter a valid payment method and try again. ' ,
363
+ $ exceptionData ['errors ' ][0 ]['message ' ]
364
+ );
365
+ self ::assertEquals (
366
+ ErrorMapper::ERROR_UNABLE_TO_PLACE_ORDER ,
367
+ $ exceptionData ['errors ' ][0 ]['extensions ' ]['error_code ' ]
368
+ );
369
+ }
321
370
}
322
371
323
372
#[
@@ -348,13 +397,20 @@ public function testPlaceOrderWithOutOfStockProduct()
348
397
$ cart = DataFixtureStorageManager::getStorage ()->get ('cart ' );
349
398
$ maskedQuoteId = $ this ->quoteIdToMaskedQuoteIdInterface ->execute ((int ) $ cart ->getId ());
350
399
$ query = $ this ->getQuery ($ maskedQuoteId );
351
- $ response = $ this ->graphQlMutation ($ query );
352
- self ::assertEquals (1 , count ($ response ['placeOrder ' ]['errors ' ]));
353
- self ::assertEquals ('UNABLE_TO_PLACE_ORDER ' , $ response ['placeOrder ' ]['errors ' ][0 ]['code ' ]);
354
- self ::assertEquals (
355
- 'Some of the products are out of stock. ' ,
356
- $ response ['placeOrder ' ]['errors ' ][0 ]['message ' ]
357
- );
400
+ try {
401
+ $ this ->graphQlMutation ($ query );
402
+ } catch (ResponseContainsErrorsException $ exception ) {
403
+ $ exceptionData = $ exception ->getResponseData ();
404
+ self ::assertEquals (1 , count ($ exceptionData ['errors ' ]));
405
+ self ::assertEquals (
406
+ 'Unable to place order: Some of the products are out of stock. ' ,
407
+ $ exceptionData ['errors ' ][0 ]['message ' ]
408
+ );
409
+ self ::assertEquals (
410
+ ErrorMapper::ERROR_UNABLE_TO_PLACE_ORDER ,
411
+ $ exceptionData ['errors ' ][0 ]['extensions ' ]['error_code ' ]
412
+ );
413
+ }
358
414
}
359
415
360
416
#[
@@ -385,13 +441,20 @@ public function testPlaceOrderWithOutOfStockProductWithDisabledInventoryCheck()
385
441
$ cart = DataFixtureStorageManager::getStorage ()->get ('cart ' );
386
442
$ maskedQuoteId = $ this ->quoteIdToMaskedQuoteIdInterface ->execute ((int ) $ cart ->getId ());
387
443
$ query = $ this ->getQuery ($ maskedQuoteId );
388
- $ response = $ this ->graphQlMutation ($ query );
389
- self ::assertEquals (1 , count ($ response ['placeOrder ' ]['errors ' ]));
390
- self ::assertEquals ('UNABLE_TO_PLACE_ORDER ' , $ response ['placeOrder ' ]['errors ' ][0 ]['code ' ]);
391
- self ::assertEquals (
392
- 'Enter a valid payment method and try again. ' ,
393
- $ response ['placeOrder ' ]['errors ' ][0 ]['message ' ]
394
- );
444
+ try {
445
+ $ this ->graphQlMutation ($ query );
446
+ } catch (ResponseContainsErrorsException $ exception ) {
447
+ $ exceptionData = $ exception ->getResponseData ();
448
+ self ::assertEquals (1 , count ($ exceptionData ['errors ' ]));
449
+ self ::assertEquals (
450
+ 'Unable to place order: Enter a valid payment method and try again. ' ,
451
+ $ exceptionData ['errors ' ][0 ]['message ' ]
452
+ );
453
+ self ::assertEquals (
454
+ ErrorMapper::ERROR_UNABLE_TO_PLACE_ORDER ,
455
+ $ exceptionData ['errors ' ][0 ]['extensions ' ]['error_code ' ]
456
+ );
457
+ }
395
458
}
396
459
397
460
#[
0 commit comments