Skip to content

Commit 7d0d006

Browse files
author
Prabhu Ram
committed
Merge branch 'MC-36897' of github.com:magento-honey-badgers/magento2ce into MC-36897
2 parents 1b08a0c + 4ac627e commit 7d0d006

File tree

2 files changed

+168
-0
lines changed

2 files changed

+168
-0
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/CustomerWishlistTest.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,78 @@ public function testGuestCannotGetWishlist()
124124
$this->graphQlQuery($query);
125125
}
126126

127+
/**
128+
* Add product to wishlist with quantity 0
129+
*
130+
* @magentoConfigFixture default_store wishlist/general/active 1
131+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
132+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_duplicated.php
133+
*/
134+
public function testAddProductToWishlistWithZeroQty()
135+
{
136+
$customerWishlistQuery =
137+
<<<QUERY
138+
{
139+
customer {
140+
wishlist {
141+
id
142+
}
143+
}
144+
}
145+
QUERY;
146+
147+
$response = $this->graphQlQuery(
148+
$customerWishlistQuery,
149+
[],
150+
'',
151+
$this->getCustomerAuthHeaders('customer@example.com', 'password')
152+
);
153+
$qty = 0;
154+
$sku = 'simple-1';
155+
$wishlistId = $response['customer']['wishlist']['id'];
156+
$addProductToWishlistQuery =
157+
<<<QUERY
158+
mutation{
159+
addProductsToWishlist(
160+
wishlistId:{$wishlistId}
161+
wishlistItems:[
162+
{
163+
sku:"{$sku}"
164+
quantity:{$qty}
165+
}
166+
])
167+
{
168+
wishlist{
169+
id
170+
items_count
171+
items{product{name sku} description qty}
172+
}
173+
user_errors{code message}
174+
}
175+
}
176+
177+
QUERY;
178+
$addToWishlistResponse = $this->graphQlMutation(
179+
$addProductToWishlistQuery,
180+
[],
181+
'',
182+
$this->getCustomerAuthHeaders('customer@example.com', 'password')
183+
);
184+
$this->assertArrayHasKey('user_errors', $addToWishlistResponse['addProductsToWishlist']);
185+
$this->assertCount(1, $addToWishlistResponse['addProductsToWishlist']['user_errors']);
186+
$this->assertEmpty($addToWishlistResponse['addProductsToWishlist']['wishlist']['items']);
187+
$this->assertEquals(
188+
0,
189+
$addToWishlistResponse['addProductsToWishlist']['wishlist']['items_count'],
190+
'Count is greater than 0'
191+
);
192+
$message = 'The quantity of a wish list item cannot be 0';
193+
$this->assertEquals(
194+
$message,
195+
$addToWishlistResponse['addProductsToWishlist']['user_errors'][0]['message']
196+
);
197+
}
198+
127199
/**
128200
* @magentoConfigFixture default_store wishlist/general/active 0
129201
* @magentoApiDataFixture Magento/Customer/_files/customer.php

dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/UpdateProductsFromWishlistTest.php

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,57 @@ public function testUpdateSimpleProductFromWishlist(): void
5757
self::assertEquals($description, $wishlistResponse['items'][0]['description']);
5858
}
5959

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+
60111
/**
61112
* Authentication header map
62113
*
@@ -121,6 +172,51 @@ private function getQuery(
121172
MUTATION;
122173
}
123174

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+
124220
/**
125221
* Get wishlist result
126222
*

0 commit comments

Comments
 (0)