@@ -383,23 +383,19 @@ public function testSetShippingAddressToAnotherCustomerCart()
383
383
public function testSetNewShippingAddressWithMissedRequiredParameters (string $ input , string $ message )
384
384
{
385
385
$ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_quote ' );
386
+ $ input = str_replace ('cart_id_value ' , $ maskedQuoteId , $ input );
386
387
387
388
$ query = <<<QUERY
388
389
mutation {
389
390
setShippingAddressesOnCart(
390
391
input: {
391
- cart_id: " {$ maskedQuoteId }"
392
- shipping_addresses: [
393
- {
394
- {$ input }
395
- }
396
- ]
392
+ {$ input }
397
393
}
398
394
) {
399
395
cart {
400
- shipping_addresses {
401
- city
402
- }
396
+ shipping_addresses {
397
+ city
398
+ }
403
399
}
404
400
}
405
401
}
@@ -414,13 +410,18 @@ public function testSetNewShippingAddressWithMissedRequiredParameters(string $in
414
410
public function dataProviderUpdateWithMissedRequiredParameters (): array
415
411
{
416
412
return [
417
- 'shipping_addresses ' => [
418
- '' ,
419
- 'The shipping address must contain either "customer_address_id" or "address". ' ,
413
+ 'missed_shipping_addresses ' => [
414
+ 'cart_id: "cart_id_value" ' ,
415
+ 'Field SetShippingAddressesOnCartInput.shipping_addresses of required type [ShippingAddressInput]! ' .
416
+ 'was not provided. ' ,
420
417
],
421
418
'missed_city ' => [
422
- 'address: { save_in_address_book: false } ' ,
419
+ 'shipping_addresses: [ { address: { save_in_address_book: false } } ] ' ,
423
420
'Field CartAddressInput.city of required type String! was not provided '
421
+ ],
422
+ 'missed_cart_id ' => [
423
+ 'shipping_addresses: {} ' ,
424
+ 'Required parameter "cart_id" is missing '
424
425
]
425
426
];
426
427
}
@@ -532,6 +533,75 @@ public function testSetNewShippingAddressOnCartWithRedundantStreetLine()
532
533
$ this ->graphQlMutation ($ query , [], '' , $ this ->getHeaderMap ());
533
534
}
534
535
536
+ /**
537
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
538
+ * @magentoApiDataFixture Magento/Customer/_files/customer_address.php
539
+ * @expectedException \Exception
540
+ * @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
541
+ */
542
+ public function testSetShippingAddressOnNonExistentCart ()
543
+ {
544
+ $ maskedQuoteId = 'non_existent_masked_id ' ;
545
+ $ query = <<<QUERY
546
+ mutation {
547
+ setShippingAddressesOnCart(
548
+ input: {
549
+ cart_id: " $ maskedQuoteId"
550
+ shipping_addresses: [
551
+ {
552
+ customer_address_id: 1
553
+ }
554
+ ]
555
+ }
556
+ ) {
557
+ cart {
558
+ shipping_addresses {
559
+ city
560
+ }
561
+ }
562
+ }
563
+ }
564
+ QUERY ;
565
+ $ this ->graphQlMutation ($ query , [], '' , $ this ->getHeaderMap ());
566
+ }
567
+
568
+ /**
569
+ * _security
570
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
571
+ * @magentoApiDataFixture Magento/Customer/_files/customer_address.php
572
+ * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
573
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
574
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
575
+ */
576
+ public function testSetShippingAddressToGuestCart ()
577
+ {
578
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_quote ' );
579
+
580
+ $ query = <<<QUERY
581
+ mutation {
582
+ setShippingAddressesOnCart(
583
+ input: {
584
+ cart_id: " $ maskedQuoteId"
585
+ shipping_addresses: {
586
+ customer_address_id: 1
587
+ }
588
+ }
589
+ ) {
590
+ cart {
591
+ shipping_addresses {
592
+ city
593
+ }
594
+ }
595
+ }
596
+ }
597
+ QUERY ;
598
+ $ this ->expectExceptionMessage (
599
+ "The current user cannot perform operations on cart \"{$ maskedQuoteId }\""
600
+ );
601
+
602
+ $ this ->graphQlMutation ($ query , [], '' , $ this ->getHeaderMap ());
603
+ }
604
+
535
605
/**
536
606
* Verify the all the whitelisted fields for a New Address Object
537
607
*
@@ -594,7 +664,8 @@ private function getHeaderMap(string $username = 'customer@example.com', string
594
664
private function assignQuoteToCustomer (
595
665
string $ reservedOrderId = 'test_order_with_simple_product_without_address ' ,
596
666
int $ customerId = 1
597
- ): string {
667
+ ): string
668
+ {
598
669
$ quote = $ this ->quoteFactory ->create ();
599
670
$ this ->quoteResource ->load ($ quote , $ reservedOrderId , 'reserved_order_id ' );
600
671
$ quote ->setCustomerId ($ customerId );
0 commit comments