@@ -199,6 +199,39 @@ public function testAddProductWithWrongQuantity(int $quantity, string $message)
199199 );
200200 }
201201
202+ /**
203+ * @magentoApiDataFixture Magento/Catalog/_files/products_with_websites_and_stores.php
204+ * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
205+ * @magentoApiDataFixture Magento/Checkout/_files/active_quote_not_default_website.php
206+ * @dataProvider addProductNotAssignedToWebsiteDataProvider
207+ * @param string $reservedOrderId
208+ * @param string $sku
209+ * @param array $headerMap
210+ */
211+ public function testAddProductNotAssignedToWebsite (string $ reservedOrderId , string $ sku , array $ headerMap )
212+ {
213+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ($ reservedOrderId );
214+ $ query = $ this ->getAddToCartMutation ($ maskedQuoteId , 1 , $ sku );
215+ $ response = $ this ->graphQlMutation ($ query , [], '' , $ headerMap );
216+ self ::assertEmpty ($ response ['addProductsToCart ' ]['cart ' ]['items ' ]);
217+ self ::assertArrayHasKey ('user_errors ' , $ response ['addProductsToCart ' ]);
218+ self ::assertCount (1 , $ response ['addProductsToCart ' ]['user_errors ' ]);
219+ self ::assertStringContainsString ($ sku , $ response ['addProductsToCart ' ]['user_errors ' ][0 ]['message ' ]);
220+ self ::assertEquals ('PRODUCT_NOT_FOUND ' , $ response ['addProductsToCart ' ]['user_errors ' ][0 ]['code ' ]);
221+ }
222+
223+ /**
224+ * @return array
225+ */
226+ public function addProductNotAssignedToWebsiteDataProvider (): array
227+ {
228+ return [
229+ ['test_order_1 ' , 'simple-2 ' , []],
230+ ['test_order_1 ' , 'simple-2 ' , ['Store ' => 'default ' ]],
231+ ['test_order_2 ' , 'simple-1 ' , ['Store ' => 'fixture_second_store ' ]],
232+ ];
233+ }
234+
202235 /**
203236 * @return array
204237 */
@@ -246,7 +279,7 @@ private function getAddToCartMutation(
246279 string $ maskedQuoteId ,
247280 int $ qty ,
248281 string $ sku ,
249- string $ customizableOptions
282+ string $ customizableOptions = ''
250283 ): string {
251284 return <<<MUTATION
252285mutation {
@@ -279,6 +312,7 @@ private function getAddToCartMutation(
279312 }
280313 },
281314 user_errors {
315+ code
282316 message
283317 }
284318 }
0 commit comments