Skip to content

Commit 56ebc38

Browse files
AC-5986::Unable to update cart item custom option values with REST API-fixed static test failure
1 parent 7e64392 commit 56ebc38

File tree

1 file changed

+82
-99
lines changed

1 file changed

+82
-99
lines changed

dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartAddingItemsTest.php

Lines changed: 82 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@
77

88
namespace Magento\Quote\Api;
99

10+
use Magento\Framework\Webapi\Rest\Request;
11+
use Magento\Quote\Model\Quote;
1012
use Magento\TestFramework\TestCase\WebapiAbstract;
1113

1214
/**
1315
* Class for testing adding and deleting items flow.
1416
*/
1517
class GuestCartAddingItemsTest extends WebapiAbstract
1618
{
17-
const SERVICE_VERSION = 'V1';
18-
const SERVICE_NAME = 'quoteGuestCartManagementV1';
19-
const RESOURCE_PATH = '/V1/guest-carts/';
19+
private const SERVICE_VERSION = 'V1';
20+
private const SERVICE_NAME = 'quoteGuestCartManagementV1';
21+
private const RESOURCE_PATH = '/V1/guest-carts/';
2022

2123
/**
2224
* @var \Magento\TestFramework\ObjectManager
@@ -29,108 +31,91 @@ protected function setUp(): void
2931
}
3032

3133
/**
32-
* Test price for cart after deleting and adding product to.
34+
* Test add to product with custom option and test with updating custom options.
3335
*
34-
* @magentoApiDataFixture Magento/Catalog/_files/product_without_options_with_stock_data.php
36+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_custom_options.php
3537
* @return void
3638
*/
37-
public function testPriceForCreatingQuoteFromEmptyCart()
39+
public function testAddtoCartWithCustomOptionsForCreatingQuoteFromEmptyCart()
3840
{
41+
$this->_markTestAsRestOnly();
3942
// Creating empty cart
4043
$serviceInfoForCreatingEmptyCart = [
4144
'rest' => [
4245
'resourcePath' => self::RESOURCE_PATH,
43-
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
44-
],
45-
'soap' => [
46-
'service' => self::SERVICE_NAME,
47-
'serviceVersion' => self::SERVICE_VERSION,
48-
'operation' => self::SERVICE_NAME . 'CreateEmptyCart',
49-
],
46+
'httpMethod' => Request::HTTP_METHOD_POST,
47+
]
5048
];
5149
$quoteId = $this->_webApiCall($serviceInfoForCreatingEmptyCart);
5250

5351
// Adding item to the cart
5452
$serviceInfoForAddingProduct = [
5553
'rest' => [
5654
'resourcePath' => self::RESOURCE_PATH . $quoteId . '/items',
57-
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
58-
],
59-
'soap' => [
60-
'service' => GuestCartItemRepositoryTest::SERVICE_NAME,
61-
'serviceVersion' => self::SERVICE_VERSION,
62-
'operation' => GuestCartItemRepositoryTest::SERVICE_NAME . 'Save',
63-
],
55+
'httpMethod' => Request::HTTP_METHOD_POST,
56+
]
6457
];
6558
$requestData = [
6659
'cartItem' => [
6760
'quote_id' => $quoteId,
68-
'sku' => 'simple',
69-
'qty' => 1
61+
'sku' => 'simple_with_custom_options',
62+
'qty' => 1,
63+
'product_option' => [
64+
'extension_attributes' => [
65+
'custom_options' => [
66+
['option_id' => 1, 'option_value' => 1],
67+
['option_id' => 2, 'option_value' => 1],
68+
['option_id' => 3, 'option_value' => 'test']
69+
]
70+
]
71+
]
7072
]
7173
];
7274
$item = $this->_webApiCall($serviceInfoForAddingProduct, $requestData);
7375
$this->assertNotEmpty($item);
7476

75-
// Delete the item for the cart
76-
$serviceInfoForDeleteProduct = [
77-
'rest' => [
78-
'resourcePath' => self::RESOURCE_PATH . $quoteId . '/items/' . $item['item_id'],
79-
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_DELETE,
80-
],
81-
'soap' => [
82-
'service' => GuestCartItemRepositoryTest::SERVICE_NAME,
83-
'serviceVersion' => self::SERVICE_VERSION,
84-
'operation' => GuestCartItemRepositoryTest::SERVICE_NAME . 'deleteById',
85-
],
86-
];
87-
$response = (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) ?
88-
$this->_webApiCall($serviceInfoForDeleteProduct, ['cartId' => $quoteId, 'itemId' => $item['item_id']])
89-
: $this->_webApiCall($serviceInfoForDeleteProduct);
90-
$this->assertTrue($response);
91-
92-
// Add one more item and check price for this item
93-
$serviceInfoForAddingProduct = [
94-
'rest' => [
95-
'resourcePath' => self::RESOURCE_PATH . $quoteId . '/items',
96-
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
97-
],
98-
'soap' => [
99-
'service' => GuestCartItemRepositoryTest::SERVICE_NAME,
100-
'serviceVersion' => self::SERVICE_VERSION,
101-
'operation' => GuestCartItemRepositoryTest::SERVICE_NAME . 'Save',
102-
],
103-
];
10477
$requestData = [
10578
'cartItem' => [
10679
'quote_id' => $quoteId,
107-
'sku' => 'simple',
108-
'qty' => 1
80+
'sku' => 'simple_with_custom_options',
81+
'qty' => 1,
82+
'product_option' => [
83+
'extension_attributes' => [
84+
'custom_options' => [
85+
['option_id' => 1, 'option_value' => 2],
86+
['option_id' => 2, 'option_value' => 2],
87+
['option_id' => 3, 'option_value' => 'test2']
88+
]
89+
]
90+
]
10991
]
11092
];
111-
$item = $this->_webApiCall($serviceInfoForAddingProduct, $requestData);
112-
$this->assertNotEmpty($item);
113-
$this->assertEquals($item['price'], 10);
11493

115-
/** @var \Magento\Quote\Model\Quote $quote */
116-
$quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
117-
$quote->load($quoteId);
118-
$quote->delete();
94+
// Update the item for the cart
95+
$serviceInfoForUpdateProduct = [
96+
'rest' => [
97+
'resourcePath' => self::RESOURCE_PATH . $quoteId . '/items/' . $item['item_id'],
98+
'httpMethod' => Request::HTTP_METHOD_PUT,
99+
]
100+
];
101+
102+
$item = $this->_webApiCall($serviceInfoForUpdateProduct, $requestData);
103+
$this->assertNotEmpty($item);
119104
}
120105

121106
/**
122-
* Test add to product with custom option and test with updating custom options.
107+
* Test price for cart after deleting and adding product to.
123108
*
124-
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_custom_options.php
109+
* @magentoApiDataFixture Magento/Catalog/_files/product_without_options_with_stock_data.php
125110
* @return void
126111
*/
127-
public function testAddtoCartWithCustomOptionsForCreatingQuoteFromEmptyCart()
112+
public function testPriceForCreatingQuoteFromEmptyCart()
128113
{
129114
// Creating empty cart
130115
$serviceInfoForCreatingEmptyCart = [
131116
'rest' => [
132117
'resourcePath' => self::RESOURCE_PATH,
133-
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
118+
'httpMethod' => Request::HTTP_METHOD_POST,
134119
],
135120
'soap' => [
136121
'service' => self::SERVICE_NAME,
@@ -144,7 +129,7 @@ public function testAddtoCartWithCustomOptionsForCreatingQuoteFromEmptyCart()
144129
$serviceInfoForAddingProduct = [
145130
'rest' => [
146131
'resourcePath' => self::RESOURCE_PATH . $quoteId . '/items',
147-
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
132+
'httpMethod' => Request::HTTP_METHOD_POST,
148133
],
149134
'soap' => [
150135
'service' => GuestCartItemRepositoryTest::SERVICE_NAME,
@@ -155,57 +140,55 @@ public function testAddtoCartWithCustomOptionsForCreatingQuoteFromEmptyCart()
155140
$requestData = [
156141
'cartItem' => [
157142
'quote_id' => $quoteId,
158-
'sku' => 'simple_with_custom_options',
159-
'qty' => 1,
160-
'product_option' => [
161-
'extension_attributes' => [
162-
'custom_options' => [
163-
['option_id' => 1, 'option_value' => 1],
164-
['option_id' => 2, 'option_value' => 1],
165-
['option_id' => 3, 'option_value' => 'test']
166-
]
167-
]
168-
]
143+
'sku' => 'simple',
144+
'qty' => 1
169145
]
170146
];
171147
$item = $this->_webApiCall($serviceInfoForAddingProduct, $requestData);
172148
$this->assertNotEmpty($item);
173149

174-
$requestData = [
175-
'cartItem' => [
176-
'quote_id' => $quoteId,
177-
'sku' => 'simple_with_custom_options',
178-
'qty' => 1,
179-
'product_option' => [
180-
'extension_attributes' => [
181-
'custom_options' => [
182-
['option_id' => 1, 'option_value' => 2],
183-
['option_id' => 2, 'option_value' => 2],
184-
['option_id' => 3, 'option_value' => 'test2']
185-
]
186-
]
187-
]
188-
]
150+
// Delete the item for the cart
151+
$serviceInfoForDeleteProduct = [
152+
'rest' => [
153+
'resourcePath' => self::RESOURCE_PATH . $quoteId . '/items/' . $item['item_id'],
154+
'httpMethod' => Request::HTTP_METHOD_DELETE,
155+
],
156+
'soap' => [
157+
'service' => GuestCartItemRepositoryTest::SERVICE_NAME,
158+
'serviceVersion' => self::SERVICE_VERSION,
159+
'operation' => GuestCartItemRepositoryTest::SERVICE_NAME . 'deleteById',
160+
],
189161
];
162+
$response = (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) ?
163+
$this->_webApiCall($serviceInfoForDeleteProduct, ['cartId' => $quoteId, 'itemId' => $item['item_id']])
164+
: $this->_webApiCall($serviceInfoForDeleteProduct);
165+
$this->assertTrue($response);
190166

191-
// Update the item for the cart
192-
$serviceInfoForUpdateProduct = [
167+
// Add one more item and check price for this item
168+
$serviceInfoForAddingProduct = [
193169
'rest' => [
194-
'resourcePath' => self::RESOURCE_PATH . $quoteId . '/items/' . $item['item_id'],
195-
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
170+
'resourcePath' => self::RESOURCE_PATH . $quoteId . '/items',
171+
'httpMethod' => Request::HTTP_METHOD_POST,
196172
],
197173
'soap' => [
198174
'service' => GuestCartItemRepositoryTest::SERVICE_NAME,
199175
'serviceVersion' => self::SERVICE_VERSION,
200176
'operation' => GuestCartItemRepositoryTest::SERVICE_NAME . 'Save',
201177
],
202178
];
203-
204-
$item = $this->_webApiCall($serviceInfoForUpdateProduct, $requestData);
179+
$requestData = [
180+
'cartItem' => [
181+
'quote_id' => $quoteId,
182+
'sku' => 'simple',
183+
'qty' => 1
184+
]
185+
];
186+
$item = $this->_webApiCall($serviceInfoForAddingProduct, $requestData);
205187
$this->assertNotEmpty($item);
188+
$this->assertEquals($item['price'], 10);
206189

207-
/** @var \Magento\Quote\Model\Quote $quote */
208-
$quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
190+
/** @var Quote $quote */
191+
$quote = $this->objectManager->create(Quote::class);
209192
$quote->load($quoteId);
210193
$quote->delete();
211194
}

0 commit comments

Comments
 (0)