Skip to content

Commit 14d5c3d

Browse files
committed
Merge remote-tracking branch 'yogeshsuhagiya/2.3-develop-graphql-PR-yogesh-5' into 2.3-develop-graphql-PR-yogesh-5
2 parents f01dc00 + c2f15b3 commit 14d5c3d

File tree

1 file changed

+30
-48
lines changed

1 file changed

+30
-48
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php

Lines changed: 30 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,25 @@ public function testShippingMethodWithVirtualProduct()
7171
);
7272

7373
self::expectException(\Exception::class);
74-
self::expectExceptionMessage('Carrier with such method not found: ' . $methodCode . ', ' . $methodCode . '');
74+
self::expectExceptionMessage('You can\'t set shipping methods for virtual products');
7575
$this->graphQlQuery($query);
7676
}
7777

7878
/**
79-
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
79+
* @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php
8080
*/
8181
public function testShippingMethodWithSimpleProduct()
8282
{
8383
$methodCode = 'flatrate';
8484
$carrierCode = 'flatrate';
85-
$reservedOrderId = 'test_order_with_simple_product_without_address';
85+
$reservedOrderId = 'guest_quote';
8686

8787
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId);
88-
$quoteAddressId = $this->getQuoteAddressIdByReversedQuoteId($reservedOrderId);
88+
89+
/** @var Quote $quote */
90+
$quote = $this->quoteFactory->create();
91+
$this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id');
92+
$quoteAddressId = (int) $quote->getShippingAddress()->getId();
8993

9094
$query = $this->prepareMutationQuery(
9195
$maskedQuoteId,
@@ -108,28 +112,42 @@ public function testShippingMethodWithSimpleProduct()
108112

109113
/**
110114
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
115+
* @dataProvider dataProviderWithMissedRequiredParameters
116+
* @param int $addressId
117+
* @param string $message
111118
* @expectedException \Exception
112-
* @expectedExceptionMessage Required parameter "cart_address_id" is missing.
113119
*/
114-
public function testShippingMethodWithSimpleProductWithoutAddress()
120+
public function testShippingMethodWithSimpleProductWithoutAddress(int $addressId, string $message)
115121
{
116122
$methodCode = 'flatrate';
117123
$carrierCode = 'flatrate';
118124
$reservedOrderId = 'test_order_with_simple_product_without_address';
119125

120126
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId);
121-
$quoteAddressId = 0;
122-
123127
$query = $this->prepareMutationQuery(
124128
$maskedQuoteId,
125129
$methodCode,
126130
$carrierCode,
127-
$quoteAddressId
131+
$addressId
128132
);
129133

134+
$this->expectExceptionMessage($message);
130135
$this->graphQlQuery($query);
131136
}
132137

138+
/**
139+
* @return array
140+
*/
141+
public function dataProviderWithMissedRequiredParameters()
142+
{
143+
return [
144+
'shipping_methods' => [
145+
0,
146+
'Required parameter "cart_address_id" is missing.',
147+
]
148+
];
149+
}
150+
133151
/**
134152
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
135153
* @expectedException \Exception
@@ -213,16 +231,15 @@ public function testSetShippingMethodIfAddressIsNotBelongToCart()
213231

214232
/**
215233
* @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php
216-
* @expectedException \Magento\Framework\Exception\NoSuchEntityException
217-
* @expectedExceptionMessage No such entity with cartId = 0
234+
* @expectedException \Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException
235+
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
218236
*/
219237
public function testSetShippingMethodToNonExistentCart()
220238
{
221239
$methodCode = 'flatrate';
222240
$carrierCode = 'flatrate';
223-
$reservedOrderId = 'non_existent_cart_reversed_quote_id';
224241

225-
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId);
242+
$maskedQuoteId = 'non_existent_masked_id';
226243
$quoteAddressId = 1;
227244

228245
$query = $this->prepareMutationQuery(
@@ -235,41 +252,6 @@ public function testSetShippingMethodToNonExistentCart()
235252
$this->graphQlQuery($query);
236253
}
237254

238-
/**
239-
* @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php
240-
*/
241-
public function testSetShippingMethodToGuestCart()
242-
{
243-
$methodCode = 'flatrate';
244-
$carrierCode = 'flatrate';
245-
$reservedOrderId = 'guest_quote';
246-
247-
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId);
248-
249-
/** @var Quote $quote */
250-
$quote = $this->quoteFactory->create();
251-
$this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id');
252-
$quoteAddressId = (int) $quote->getShippingAddress()->getId();
253-
254-
$query = $this->prepareMutationQuery(
255-
$maskedQuoteId,
256-
$methodCode,
257-
$carrierCode,
258-
$quoteAddressId
259-
);
260-
261-
$response = $this->graphQlQuery($query);
262-
263-
self::assertArrayHasKey('setShippingMethodsOnCart', $response);
264-
self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']);
265-
self::assertArrayHasKey('shipping_addresses', $response['setShippingMethodsOnCart']['cart']);
266-
267-
$shippingMethod = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']);
268-
self::assertArrayHasKey('selected_shipping_method', $shippingMethod);
269-
self::assertEquals($carrierCode, $shippingMethod['selected_shipping_method']['carrier_code']);
270-
self::assertEquals($methodCode, $shippingMethod['selected_shipping_method']['method_code']);
271-
}
272-
273255
/**
274256
* @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php
275257
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php

0 commit comments

Comments
 (0)