From 16ce0467b88b7ded25b9d1e25bd1393784a615c2 Mon Sep 17 00:00:00 2001 From: Yogesh Suhagiya Date: Tue, 26 Mar 2019 12:16:55 +0530 Subject: [PATCH 1/2] Removed duplicate case & applied logic fixes --- .../Guest/SetShippingMethodsOnCartTest.php | 75 +++++++------------ 1 file changed, 27 insertions(+), 48 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php index f6444027d0ca3..eadc131ee464a 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php @@ -71,21 +71,25 @@ public function testShippingMethodWithVirtualProduct() ); self::expectException(\Exception::class); - self::expectExceptionMessage('Carrier with such method not found: ' . $methodCode . ', ' . $methodCode . ''); + self::expectExceptionMessage('You can\'t set shipping methods for virtual products'); $this->graphQlQuery($query); } /** - * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php */ public function testShippingMethodWithSimpleProduct() { $methodCode = 'flatrate'; $carrierCode = 'flatrate'; - $reservedOrderId = 'test_order_with_simple_product_without_address'; + $reservedOrderId = 'guest_quote'; $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); - $quoteAddressId = $this->getQuoteAddressIdByReversedQuoteId($reservedOrderId); + + /** @var Quote $quote */ + $quote = $this->quoteFactory->create(); + $this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id'); + $quoteAddressId = (int) $quote->getShippingAddress()->getId(); $query = $this->prepareMutationQuery( $maskedQuoteId, @@ -109,27 +113,38 @@ public function testShippingMethodWithSimpleProduct() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php * @expectedException \Exception - * @expectedExceptionMessage Required parameter "cart_address_id" is missing. */ - public function testShippingMethodWithSimpleProductWithoutAddress() + public function testShippingMethodWithSimpleProductWithoutAddress(int $addressId, string $message) { $methodCode = 'flatrate'; $carrierCode = 'flatrate'; $reservedOrderId = 'test_order_with_simple_product_without_address'; $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); - $quoteAddressId = 0; - $query = $this->prepareMutationQuery( $maskedQuoteId, $methodCode, $carrierCode, - $quoteAddressId + $addressId ); + $this->expectExceptionMessage($message); $this->graphQlQuery($query); } + /** + * @return array + */ + public function dataProviderWithMissedRequiredParameters() + { + return [ + 'shipping_methods' => [ + 0, + 'Required parameter "cart_address_id" is missing.', + ] + ]; + } + /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php * @expectedException \Exception @@ -213,16 +228,15 @@ public function testSetShippingMethodIfAddressIsNotBelongToCart() /** * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php - * @expectedException \Magento\Framework\Exception\NoSuchEntityException - * @expectedExceptionMessage No such entity with cartId = 0 + * @expectedException \Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException + * @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id" */ public function testSetShippingMethodToNonExistentCart() { $methodCode = 'flatrate'; $carrierCode = 'flatrate'; - $reservedOrderId = 'non_existent_cart_reversed_quote_id'; - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); + $maskedQuoteId = 'non_existent_masked_id'; $quoteAddressId = 1; $query = $this->prepareMutationQuery( @@ -235,41 +249,6 @@ public function testSetShippingMethodToNonExistentCart() $this->graphQlQuery($query); } - /** - * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php - */ - public function testSetShippingMethodToGuestCart() - { - $methodCode = 'flatrate'; - $carrierCode = 'flatrate'; - $reservedOrderId = 'guest_quote'; - - $maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId); - - /** @var Quote $quote */ - $quote = $this->quoteFactory->create(); - $this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id'); - $quoteAddressId = (int) $quote->getShippingAddress()->getId(); - - $query = $this->prepareMutationQuery( - $maskedQuoteId, - $methodCode, - $carrierCode, - $quoteAddressId - ); - - $response = $this->graphQlQuery($query); - - self::assertArrayHasKey('setShippingMethodsOnCart', $response); - self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']); - self::assertArrayHasKey('shipping_addresses', $response['setShippingMethodsOnCart']['cart']); - - $shippingMethod = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']); - self::assertArrayHasKey('selected_shipping_method', $shippingMethod); - self::assertEquals($carrierCode, $shippingMethod['selected_shipping_method']['carrier_code']); - self::assertEquals($methodCode, $shippingMethod['selected_shipping_method']['method_code']); - } - /** * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php From c2f15b388db0ba654920289f32a3e3e0def072e2 Mon Sep 17 00:00:00 2001 From: Yogesh Suhagiya Date: Tue, 26 Mar 2019 12:53:33 +0530 Subject: [PATCH 2/2] Added data Provider --- .../GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php index eadc131ee464a..2fc919fd86689 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php @@ -112,6 +112,9 @@ public function testShippingMethodWithSimpleProduct() /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @dataProvider dataProviderWithMissedRequiredParameters + * @param int $addressId + * @param string $message * @expectedException \Exception */ public function testShippingMethodWithSimpleProductWithoutAddress(int $addressId, string $message)