11<?php
22/**
3- * Copyright © Magento, Inc. All rights reserved.
4- * See COPYING.txt for license details .
3+ * Copyright 2020 Adobe
4+ * All Rights Reserved .
55 */
66declare (strict_types=1 );
77
88namespace Magento \GraphQl \Wishlist ;
99
1010use Exception ;
11+ use Magento \Catalog \Test \Fixture \Product as ProductFixture ;
12+ use Magento \Customer \Test \Fixture \Customer as CustomerFixture ;
1113use Magento \Framework \Exception \AuthenticationException ;
1214use Magento \Integration \Api \CustomerTokenServiceInterface ;
15+ use Magento \TestFramework \Fixture \Config ;
16+ use Magento \TestFramework \Fixture \DataFixture ;
17+ use Magento \TestFramework \Fixture \DataFixtureStorage ;
18+ use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
1319use Magento \TestFramework \Helper \Bootstrap ;
1420use Magento \TestFramework \TestCase \GraphQlAbstract ;
21+ use Magento \Wishlist \Test \Fixture \AddProductToWishlist as AddProductToWishlistFixture ;
1522
1623/**
1724 * Test coverage for updating a product from wishlist
@@ -23,12 +30,18 @@ class UpdateProductsFromWishlistTest extends GraphQlAbstract
2330 */
2431 private $ customerTokenService ;
2532
33+ /**
34+ * @var DataFixtureStorage
35+ */
36+ private $ fixtures ;
37+
2638 /**
2739 * Set Up
2840 */
2941 protected function setUp (): void
3042 {
3143 $ objectManager = Bootstrap::getObjectManager ();
44+ $ this ->fixtures = $ objectManager ->get (DataFixtureStorageManager::class)->getStorage ();
3245 $ this ->customerTokenService = $ objectManager ->get (CustomerTokenServiceInterface::class);
3346 }
3447
@@ -145,6 +158,53 @@ public function testUpdateProductWithValidQtyAndNoDescription()
145158 self ::assertEquals ('simple-1 ' , $ itemsInWishlist ['product ' ]['sku ' ]);
146159 }
147160
161+ #[
162+ Config('wishlist/general/active ' , true ),
163+ DataFixture(ProductFixture::class, as: 'product ' ),
164+ DataFixture(CustomerFixture::class, as: 'customer ' ),
165+ DataFixture(AddProductToWishlistFixture::class, [
166+ 'customer_id ' => '$customer.id$ ' ,
167+ 'product_ids ' => [
168+ '$product.id$ '
169+ ],
170+ 'name ' => 'Test Wish List ' ,
171+ ], as: 'wishlist ' )
172+ ]
173+ public function testClearWishlistDescription (): void
174+ {
175+ $ customerEmail = $ this ->fixtures ->get ('customer ' )->getEmail ();
176+ $ wishlist = $ this ->getWishlist ($ customerEmail );
177+
178+ $ customerWishlist = $ wishlist ['customer ' ]['wishlists ' ][0 ];
179+ $ wishlistId = $ customerWishlist ['id ' ];
180+ $ wishlistItem = $ customerWishlist ['items_v2 ' ]['items ' ][0 ];
181+ $ qty = 5 ;
182+ $ description = 'New Description ' ;
183+
184+ $ updateWishlistQuery = $ this ->getQuery ($ wishlistId , $ wishlistItem ['id ' ], $ qty , $ description );
185+ $ response = $ this ->graphQlMutation ($ updateWishlistQuery , [], '' , $ this ->getHeaderMap ($ customerEmail ));
186+
187+ $ this ->assertArrayHasKey ('updateProductsInWishlist ' , $ response );
188+ $ this ->assertArrayHasKey ('wishlist ' , $ response ['updateProductsInWishlist ' ]);
189+ $ wishlistResponse = $ response ['updateProductsInWishlist ' ]['wishlist ' ];
190+ $ this ->assertEquals ($ qty , $ wishlistResponse ['items_v2 ' ]['items ' ][0 ]['quantity ' ]);
191+ $ this ->assertEquals ($ description , $ wishlistResponse ['items_v2 ' ]['items ' ][0 ]['description ' ]);
192+
193+ $ updateWishlistQueryNoDescription = $ this ->getQuery ($ wishlistId , $ wishlistItem ['id ' ], $ qty , "" );
194+ $ responseNoDescription = $ this ->graphQlMutation (
195+ $ updateWishlistQueryNoDescription ,
196+ [],
197+ '' ,
198+ $ this ->getHeaderMap ($ customerEmail )
199+ );
200+
201+ $ this ->assertArrayHasKey ('updateProductsInWishlist ' , $ responseNoDescription );
202+ $ this ->assertArrayHasKey ('wishlist ' , $ responseNoDescription ['updateProductsInWishlist ' ]);
203+ $ wishlistResponseNoDescription = $ responseNoDescription ['updateProductsInWishlist ' ]['wishlist ' ];
204+ $ this ->assertEquals ($ qty , $ wishlistResponseNoDescription ['items_v2 ' ]['items ' ][0 ]['quantity ' ]);
205+ $ this ->assertEquals ('' , $ wishlistResponseNoDescription ['items_v2 ' ]['items ' ][0 ]['description ' ]);
206+ }
207+
148208 /**
149209 * Authentication header map
150210 *
0 commit comments