@@ -192,6 +192,9 @@ public function testMergeCartsWithEmptySourceCartId()
192192 */
193193 public function testMergeCartsWithEmptyDestinationCartId ()
194194 {
195+ $ this ->expectException (\Exception::class);
196+ $ this ->expectExceptionMessage ('The parameter "destination_cart_id" cannot be empty ' );
197+
195198 $ guestQuote = $ this ->quoteFactory ->create ();
196199 $ this ->quoteResource ->load (
197200 $ guestQuote ,
@@ -206,6 +209,54 @@ public function testMergeCartsWithEmptyDestinationCartId()
206209 $ this ->graphQlMutation ($ query , [], '' , $ this ->getHeaderMap ());
207210 }
208211
212+ /**
213+ * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved.php
214+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
215+ * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
216+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
217+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
218+ */
219+ public function testMergeCartsWithoutDestinationCartId ()
220+ {
221+ $ guestQuote = $ this ->quoteFactory ->create ();
222+ $ this ->quoteResource ->load (
223+ $ guestQuote ,
224+ 'test_order_with_virtual_product_without_address ' ,
225+ 'reserved_order_id '
226+ );
227+ $ guestQuoteMaskedId = $ this ->quoteIdToMaskedId ->execute ((int )$ guestQuote ->getId ());
228+ $ query = $ this ->getCartMergeMutationWithoutDestinationCartId (
229+ $ guestQuoteMaskedId
230+ );
231+ $ mergeResponse = $ this ->graphQlMutation ($ query , [], '' , $ this ->getHeaderMap ());
232+
233+ self ::assertArrayHasKey ('mergeCarts ' , $ mergeResponse );
234+ $ cartResponse = $ mergeResponse ['mergeCarts ' ];
235+ self ::assertArrayHasKey ('items ' , $ cartResponse );
236+ self ::assertCount (2 , $ cartResponse ['items ' ]);
237+
238+ $ customerQuote = $ this ->quoteFactory ->create ();
239+ $ this ->quoteResource ->load ($ customerQuote , 'test_quote ' , 'reserved_order_id ' );
240+ $ customerQuoteMaskedId = $ this ->quoteIdToMaskedId ->execute ((int )$ customerQuote ->getId ());
241+
242+ $ cartResponse = $ this ->graphQlMutation (
243+ $ this ->getCartQuery ($ customerQuoteMaskedId ),
244+ [],
245+ '' ,
246+ $ this ->getHeaderMap ()
247+ );
248+
249+ self ::assertArrayHasKey ('cart ' , $ cartResponse );
250+ self ::assertArrayHasKey ('items ' , $ cartResponse ['cart ' ]);
251+ self ::assertCount (2 , $ cartResponse ['cart ' ]['items ' ]);
252+ $ item1 = $ cartResponse ['cart ' ]['items ' ][0 ];
253+ self ::assertArrayHasKey ('quantity ' , $ item1 );
254+ self ::assertEquals (2 , $ item1 ['quantity ' ]);
255+ $ item2 = $ cartResponse ['cart ' ]['items ' ][1 ];
256+ self ::assertArrayHasKey ('quantity ' , $ item2 );
257+ self ::assertEquals (1 , $ item2 ['quantity ' ]);
258+ }
259+
209260 /**
210261 * Add simple product to cart
211262 *
@@ -253,6 +304,31 @@ private function getCartMergeMutation(string $guestQuoteMaskedId, string $custom
253304QUERY ;
254305 }
255306
307+ /**
308+ * Create the mergeCart mutation
309+ *
310+ * @param string $guestQuoteMaskedId
311+ * @return string
312+ */
313+ private function getCartMergeMutationWithoutDestinationCartId (
314+ string $ guestQuoteMaskedId
315+ ): string {
316+ return <<<QUERY
317+ mutation {
318+ mergeCarts(
319+ source_cart_id: " {$ guestQuoteMaskedId }"
320+ ){
321+ items {
322+ quantity
323+ product {
324+ sku
325+ }
326+ }
327+ }
328+ }
329+ QUERY ;
330+ }
331+
256332 /**
257333 * Get cart query
258334 *
0 commit comments