@@ -57,6 +57,57 @@ public function testUpdateSimpleProductFromWishlist(): void
57
57
self ::assertEquals ($ description , $ wishlistResponse ['items ' ][0 ]['description ' ]);
58
58
}
59
59
60
+ /**
61
+ * update the wishlist by setting an qty = 0
62
+ *
63
+ * @magentoConfigFixture default_store wishlist/general/active 1
64
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
65
+ * @magentoApiDataFixture Magento/Wishlist/_files/wishlist_with_simple_product.php
66
+ */
67
+ public function testUpdateProductInWishlistWithZeroQty ()
68
+ {
69
+ $ wishlist = $ this ->getWishlist ();
70
+ $ wishlistId = $ wishlist ['customer ' ]['wishlist ' ]['id ' ];
71
+ $ wishlistItem = $ wishlist ['customer ' ]['wishlist ' ]['items ' ][0 ];
72
+ $ qty = 0 ;
73
+ $ description = 'Description for zero quantity ' ;
74
+ $ updateWishlistQuery = $ this ->getQuery ((int ) $ wishlistId , (int ) $ wishlistItem ['id ' ], $ qty , $ description );
75
+ $ response = $ this ->graphQlMutation ($ updateWishlistQuery , [], '' , $ this ->getHeaderMap ());
76
+ self ::assertEquals (1 , $ response ['updateProductsInWishlist ' ]['wishlist ' ]['items_count ' ]);
77
+ self ::assertNotEmpty ($ response ['updateProductsInWishlist ' ]['wishlist ' ]['items ' ], 'empty wish list items ' );
78
+ self ::assertCount (1 , $ response ['updateProductsInWishlist ' ]['wishlist ' ]['items ' ]);
79
+ self ::assertArrayHasKey ('user_errors ' , $ response ['updateProductsInWishlist ' ]);
80
+ self ::assertCount (1 , $ response ['updateProductsInWishlist ' ]['user_errors ' ]);
81
+ $ message = 'The quantity of a wish list item cannot be 0 ' ;
82
+ self ::assertEquals (
83
+ $ message ,
84
+ $ response ['updateProductsInWishlist ' ]['user_errors ' ][0 ]['message ' ]
85
+ );
86
+ }
87
+
88
+ /**
89
+ * update the wishlist by setting qty to a valid value and no description
90
+ *
91
+ * @magentoConfigFixture default_store wishlist/general/active 1
92
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
93
+ * @magentoApiDataFixture Magento/Wishlist/_files/wishlist_with_simple_product.php
94
+ */
95
+ public function testUpdateProductWithValidQtyAndNoDescription ()
96
+ {
97
+ $ wishlist = $ this ->getWishlist ();
98
+ $ wishlistId = $ wishlist ['customer ' ]['wishlist ' ]['id ' ];
99
+ $ wishlistItem = $ wishlist ['customer ' ]['wishlist ' ]['items ' ][0 ];
100
+ $ qty = 2 ;
101
+ $ updateWishlistQuery = $ this ->getQueryWithNoDescription ((int ) $ wishlistId , (int ) $ wishlistItem ['id ' ], $ qty );
102
+ $ response = $ this ->graphQlMutation ($ updateWishlistQuery , [], '' , $ this ->getHeaderMap ());
103
+ self ::assertEquals (1 , $ response ['updateProductsInWishlist ' ]['wishlist ' ]['items_count ' ]);
104
+ self ::assertNotEmpty ($ response ['updateProductsInWishlist ' ]['wishlist ' ]['items ' ], 'empty wish list items ' );
105
+ self ::assertCount (1 , $ response ['updateProductsInWishlist ' ]['wishlist ' ]['items ' ]);
106
+ $ itemsInWishlist = $ response ['updateProductsInWishlist ' ]['wishlist ' ]['items ' ][0 ];
107
+ self ::assertEquals ($ qty , $ itemsInWishlist ['qty ' ]);
108
+ self ::assertEquals ('simple-1 ' , $ itemsInWishlist ['product ' ]['sku ' ]);
109
+ }
110
+
60
111
/**
61
112
* Authentication header map
62
113
*
@@ -121,6 +172,51 @@ private function getQuery(
121
172
MUTATION ;
122
173
}
123
174
175
+ /**
176
+ * Returns GraphQl mutation string
177
+ *
178
+ * @param int $wishlistId
179
+ * @param int $wishlistItemId
180
+ * @param int $qty
181
+ *
182
+ * @return string
183
+ */
184
+ private function getQueryWithNoDescription (
185
+ int $ wishlistId ,
186
+ int $ wishlistItemId ,
187
+ int $ qty
188
+ ): string {
189
+ return <<<MUTATION
190
+ mutation {
191
+ updateProductsInWishlist(
192
+ wishlistId: {$ wishlistId },
193
+ wishlistItems: [
194
+ {
195
+ wishlist_item_id: " {$ wishlistItemId }"
196
+ quantity: {$ qty }
197
+
198
+ }
199
+ ]
200
+ ) {
201
+ user_errors {
202
+ code
203
+ message
204
+ }
205
+ wishlist {
206
+ id
207
+ sharing_code
208
+ items_count
209
+ items {
210
+ id
211
+ qty
212
+ product{sku name}
213
+ }
214
+ }
215
+ }
216
+ }
217
+ MUTATION ;
218
+ }
219
+
124
220
/**
125
221
* Get wishlist result
126
222
*
0 commit comments