Skip to content

Commit 936a223

Browse files
committed
Added setting shipping method on cart test coverage concept
1 parent c98c3d5 commit 936a223

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GraphQl\Quote;
9+
10+
use Magento\Integration\Api\CustomerTokenServiceInterface;
11+
use Magento\Quote\Model\Quote;
12+
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
13+
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use Magento\TestFramework\TestCase\GraphQlAbstract;
16+
17+
/**
18+
* Test for setting shipping methods on cart
19+
*/
20+
class SetShippingMethodOnCartTest extends GraphQlAbstract
21+
{
22+
/**
23+
* @var CustomerTokenServiceInterface
24+
*/
25+
private $customerTokenService;
26+
27+
/**
28+
* @var QuoteResource
29+
*/
30+
private $quoteResource;
31+
32+
/**
33+
* @var Quote
34+
*/
35+
private $quote;
36+
37+
/**
38+
* @var QuoteIdToMaskedQuoteIdInterface
39+
*/
40+
private $quoteIdToMaskedId;
41+
42+
protected function setUp()
43+
{
44+
$objectManager = Bootstrap::getObjectManager();
45+
$this->quoteResource = $objectManager->create(QuoteResource::class);
46+
$this->quote = $objectManager->create(Quote::class);
47+
$this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class);
48+
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
49+
}
50+
51+
/**
52+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
53+
*/
54+
public function testSetShippingOnCart()
55+
{
56+
$this->quoteResource->load(
57+
$this->quote,
58+
'test_order_1',
59+
'reserved_order_id'
60+
);
61+
62+
$shippingAddress = $this->quote->getShippingAddress();
63+
$shippingAddressId = $shippingAddress->getId();
64+
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId());
65+
$query = <<<QUERY
66+
mutation {
67+
setShippingMethodsOnCart(input:
68+
{
69+
cart_id: "$maskedQuoteId",
70+
shipping_methods: [
71+
{
72+
shipping_method_code: "flatrate"
73+
shipping_carrier_code: "flatrate"
74+
cart_address_id: $shippingAddressId
75+
}
76+
]}) {
77+
78+
cart {
79+
cart_id,
80+
addresses {
81+
firstname
82+
lastname
83+
company
84+
address_type
85+
city
86+
street
87+
region {
88+
code
89+
label
90+
}
91+
postcode
92+
country {
93+
code
94+
label
95+
}
96+
97+
selected_shipping_method {
98+
code
99+
label
100+
}
101+
}
102+
}
103+
}
104+
}
105+
106+
QUERY;
107+
108+
$customerToken = $this->customerTokenService->createCustomerAccessToken('customer@example.com', 'password');
109+
$headerMap = ['Authorization' => 'Bearer ' . $customerToken];
110+
$response = $this->graphQlQuery($query, [], '', $headerMap);
111+
112+
self::assertArrayHasKey('setShippingMethodsOnCart', $response);
113+
self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']);
114+
self::assertEquals($maskedQuoteId, $response['setShippingMethodsOnCart']['cart']['cart_id']);
115+
116+
// TODO: check shipping method code and description
117+
}
118+
119+
// TODO: cover all other cases
120+
}

0 commit comments

Comments
 (0)