1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Spryker Commerce OS. |
5
|
|
|
* For full license information, please view the LICENSE file that was distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
declare(strict_types = 1); |
9
|
|
|
|
10
|
|
|
namespace PyzTest\Glue\CartReorder\RestApi; |
11
|
|
|
|
12
|
|
|
use Codeception\Util\HttpCode; |
13
|
|
|
use Generated\Shared\Transfer\RestCheckoutErrorTransfer; |
|
|
|
|
14
|
|
|
use PyzTest\Glue\CartReorder\CartReorderApiTester; |
15
|
|
|
use PyzTest\Glue\CartReorder\RestApi\Fixtures\ProductConcreteCartReorderRestApiFixtures; |
16
|
|
|
use Spryker\Glue\CartReorderRestApi\CartReorderRestApiConfig; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Auto-generated group annotations |
20
|
|
|
* |
21
|
|
|
* @group PyzTest |
22
|
|
|
* @group Glue |
23
|
|
|
* @group CartReorder |
24
|
|
|
* @group RestApi |
25
|
|
|
* @group ProductConcreteCartReorderRestApiCest |
26
|
|
|
* Add your own group annotations below this line |
27
|
|
|
* @group EndToEnd |
28
|
|
|
*/ |
29
|
|
|
class ProductConcreteCartReorderRestApiCest |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected const RESPONSE_CODE_PARAMETER_ORDER_REFERENCE_INVALID = '901'; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
protected const RESPONSE_DETAIL_PARAMETER_ORDER_REFERENCE_INVALID = 'orderReference => This value should not be blank.'; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @uses \Spryker\Glue\CartReorderRestApi\CartReorderRestApiConfig::ERROR_CODE_ORDER_NOT_FOUND |
43
|
|
|
* |
44
|
|
|
* @var string |
45
|
|
|
*/ |
46
|
|
|
protected const RESPONSE_CODE_ORDER_NOT_FOUND = '5801'; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @uses \Spryker\Glue\CartReorderRestApi\CartReorderRestApiConfig::ERROR_CODE_QUOTE_NOT_PROVIDED |
50
|
|
|
* |
51
|
|
|
* @var string |
52
|
|
|
*/ |
53
|
|
|
protected const ERROR_CODE_QUOTE_NOT_PROVIDED = '5802'; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var string |
57
|
|
|
*/ |
58
|
|
|
protected const RESPONSE_DETAIL_ORDER_NOT_FOUND = 'Order not found.'; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var string |
62
|
|
|
*/ |
63
|
|
|
protected const RESPONSE_DETAIL_QUOTE_NOT_PROVIDED = 'Quote not provided.'; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @uses \Spryker\Zed\PersistentCart\Communication\Plugin\CartReorder\ReplacePersistentCartReorderQuoteProviderStrategyPlugin::REORDER_STRATEGY_REPLACE |
67
|
|
|
* |
68
|
|
|
* @var string |
69
|
|
|
*/ |
70
|
|
|
protected const REORDER_STRATEGY_REPLACE = 'replace'; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var \PyzTest\Glue\CartReorder\RestApi\Fixtures\ProductConcreteCartReorderRestApiFixtures |
74
|
|
|
*/ |
75
|
|
|
protected ProductConcreteCartReorderRestApiFixtures $fixtures; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param \PyzTest\Glue\CartReorder\CartReorderApiTester $I |
79
|
|
|
* |
80
|
|
|
* @return void |
81
|
|
|
*/ |
82
|
|
|
public function loadFixtures(CartReorderApiTester $I): void |
83
|
|
|
{ |
84
|
|
|
/** @var \PyzTest\Glue\CartReorder\RestApi\Fixtures\ProductConcreteCartReorderRestApiFixtures $fixtures */ |
85
|
|
|
$fixtures = $I->loadFixtures(ProductConcreteCartReorderRestApiFixtures::class); |
86
|
|
|
|
87
|
|
|
$this->fixtures = $fixtures; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param \PyzTest\Glue\CartReorder\CartReorderApiTester $I |
92
|
|
|
* |
93
|
|
|
* @return void |
94
|
|
|
*/ |
95
|
|
|
public function requestCreateCartReorder(CartReorderApiTester $I): void |
96
|
|
|
{ |
97
|
|
|
// Arrange |
98
|
|
|
$I->authorizeCustomerToGlue($this->fixtures->getCustomerTransfer()); |
99
|
|
|
|
100
|
|
|
$saveOrderTransfer = $this->fixtures->getOrderWithConcreteProducts(); |
101
|
|
|
$requestPayload = [ |
102
|
|
|
'data' => [ |
103
|
|
|
'type' => CartReorderRestApiConfig::RESOURCE_CART_REORDER, |
104
|
|
|
'attributes' => [ |
105
|
|
|
'orderReference' => $saveOrderTransfer->getOrderReferenceOrFail(), |
106
|
|
|
], |
107
|
|
|
], |
108
|
|
|
]; |
109
|
|
|
|
110
|
|
|
// Act |
111
|
|
|
$I->sendPost($I->getCartReorderUrl(), $requestPayload); |
112
|
|
|
|
113
|
|
|
// Assert |
114
|
|
|
$this->assertCreateCartReorder($I); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @param \PyzTest\Glue\CartReorder\CartReorderApiTester $I |
119
|
|
|
* |
120
|
|
|
* @return void |
121
|
|
|
*/ |
122
|
|
|
public function requestCreateCartReorderWithReorderStrategyReplace(CartReorderApiTester $I): void |
123
|
|
|
{ |
124
|
|
|
// Arrange |
125
|
|
|
$I->authorizeCustomerToGlue($this->fixtures->getCustomerTransfer()); |
126
|
|
|
|
127
|
|
|
$saveOrderTransfer = $this->fixtures->getOrderWithConcreteProducts(); |
128
|
|
|
$requestPayload = [ |
129
|
|
|
'data' => [ |
130
|
|
|
'type' => CartReorderRestApiConfig::RESOURCE_CART_REORDER, |
131
|
|
|
'attributes' => [ |
132
|
|
|
'orderReference' => $saveOrderTransfer->getOrderReferenceOrFail(), |
133
|
|
|
'reorderStrategy' => static::REORDER_STRATEGY_REPLACE, |
134
|
|
|
], |
135
|
|
|
], |
136
|
|
|
]; |
137
|
|
|
|
138
|
|
|
// Act |
139
|
|
|
$I->sendPost($I->getCartReorderUrl(), $requestPayload); |
140
|
|
|
|
141
|
|
|
// Assert |
142
|
|
|
$this->assertCreateCartReorder($I); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @param \PyzTest\Glue\CartReorder\CartReorderApiTester $I |
147
|
|
|
* |
148
|
|
|
* @return void |
149
|
|
|
*/ |
150
|
|
|
public function requestCreateCartReorderWithNotAvailableProduct(CartReorderApiTester $I): void |
151
|
|
|
{ |
152
|
|
|
// Arrange |
153
|
|
|
$I->authorizeCustomerToGlue($this->fixtures->getCustomerTransfer()); |
154
|
|
|
|
155
|
|
|
$saveOrderTransfer = $this->fixtures->getOrderWithNotAvailableConcreteProduct(); |
156
|
|
|
$requestPayload = [ |
157
|
|
|
'data' => [ |
158
|
|
|
'type' => CartReorderRestApiConfig::RESOURCE_CART_REORDER, |
159
|
|
|
'attributes' => [ |
160
|
|
|
'orderReference' => $saveOrderTransfer->getOrderReferenceOrFail(), |
161
|
|
|
], |
162
|
|
|
], |
163
|
|
|
]; |
164
|
|
|
|
165
|
|
|
// Act |
166
|
|
|
$I->sendPost($I->getCartReorderUrl(), $requestPayload); |
167
|
|
|
|
168
|
|
|
// Assert |
169
|
|
|
$I->seeResponseCodeIs(HttpCode::CREATED); |
170
|
|
|
$I->seeResponseIsJson(); |
171
|
|
|
$I->seeResponseMatchesOpenApiSchema(); |
172
|
|
|
|
173
|
|
|
$I->amSure('The returned response includes first item.') |
174
|
|
|
->whenI() |
175
|
|
|
->assertResponseContainsItemBySku($this->fixtures->getProductConcreteTransfer1()->getSkuOrFail()); |
|
|
|
|
176
|
|
|
$I->amSure('The first item has correct quantity.') |
177
|
|
|
->whenI() |
178
|
|
|
->assertItemHasCorrectQuantity($this->fixtures->getProductConcreteTransfer1()->getSkuOrFail(), 2); |
|
|
|
|
179
|
|
|
$I->amSure('The returned response does not include second item.') |
180
|
|
|
->whenI() |
181
|
|
|
->assertResponseDoesNotContainItemBySku($this->fixtures->getNotAvailableProductConcreteTransfer()->getSkuOrFail()); |
|
|
|
|
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @param \PyzTest\Glue\CartReorder\CartReorderApiTester $I |
186
|
|
|
* |
187
|
|
|
* @return void |
188
|
|
|
*/ |
189
|
|
|
public function requestCreateReorderWithEmptyOrderReferenceParameter(CartReorderApiTester $I): void |
190
|
|
|
{ |
191
|
|
|
//Arrange |
192
|
|
|
$I->authorizeCustomerToGlue($this->fixtures->getCustomerTransfer()); |
193
|
|
|
|
194
|
|
|
$requestPayload = [ |
195
|
|
|
'data' => [ |
196
|
|
|
'type' => CartReorderRestApiConfig::RESOURCE_CART_REORDER, |
197
|
|
|
'attributes' => [ |
198
|
|
|
'orderReference' => '', |
199
|
|
|
], |
200
|
|
|
], |
201
|
|
|
]; |
202
|
|
|
|
203
|
|
|
// Act |
204
|
|
|
$I->sendPost($I->getCartReorderUrl(), $requestPayload); |
205
|
|
|
|
206
|
|
|
// Assert |
207
|
|
|
$I->seeResponseCodeIs(HttpCode::UNPROCESSABLE_ENTITY); |
208
|
|
|
$I->seeResponseIsJson(); |
209
|
|
|
$I->seeResponseMatchesOpenApiSchema(); |
210
|
|
|
|
211
|
|
|
$errors = $I->getDataFromResponseByJsonPath('$.errors[0]'); |
212
|
|
|
$I->assertEquals($errors[RestCheckoutErrorTransfer::CODE], static::RESPONSE_CODE_PARAMETER_ORDER_REFERENCE_INVALID); |
213
|
|
|
$I->assertEquals($errors[RestCheckoutErrorTransfer::STATUS], HttpCode::UNPROCESSABLE_ENTITY); |
214
|
|
|
$I->assertEquals($errors[RestCheckoutErrorTransfer::DETAIL], static::RESPONSE_DETAIL_PARAMETER_ORDER_REFERENCE_INVALID); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* @param \PyzTest\Glue\CartReorder\CartReorderApiTester $I |
219
|
|
|
* |
220
|
|
|
* @return void |
221
|
|
|
*/ |
222
|
|
|
public function requestCreateReorderWithNonExistingOrderReference(CartReorderApiTester $I): void |
223
|
|
|
{ |
224
|
|
|
//Arrange |
225
|
|
|
$I->authorizeCustomerToGlue($this->fixtures->getCustomerTransfer()); |
226
|
|
|
|
227
|
|
|
$requestPayload = [ |
228
|
|
|
'data' => [ |
229
|
|
|
'type' => CartReorderRestApiConfig::RESOURCE_CART_REORDER, |
230
|
|
|
'attributes' => [ |
231
|
|
|
'orderReference' => 'non-existing-order-reference', |
232
|
|
|
], |
233
|
|
|
], |
234
|
|
|
]; |
235
|
|
|
|
236
|
|
|
// Act |
237
|
|
|
$I->sendPost($I->getCartReorderUrl(), $requestPayload); |
238
|
|
|
|
239
|
|
|
// Assert |
240
|
|
|
$I->seeResponseCodeIs(HttpCode::UNPROCESSABLE_ENTITY); |
241
|
|
|
$I->seeResponseIsJson(); |
242
|
|
|
$I->seeResponseMatchesOpenApiSchema(); |
243
|
|
|
|
244
|
|
|
$errors = $I->getDataFromResponseByJsonPath('$.errors[0]'); |
245
|
|
|
$I->assertEquals($errors[RestCheckoutErrorTransfer::CODE], static::RESPONSE_CODE_ORDER_NOT_FOUND); |
246
|
|
|
$I->assertEquals($errors[RestCheckoutErrorTransfer::STATUS], HttpCode::UNPROCESSABLE_ENTITY); |
247
|
|
|
$I->assertEquals($errors[RestCheckoutErrorTransfer::DETAIL], static::RESPONSE_DETAIL_ORDER_NOT_FOUND); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @param \PyzTest\Glue\CartReorder\CartReorderApiTester $I |
252
|
|
|
* |
253
|
|
|
* @return void |
254
|
|
|
*/ |
255
|
|
|
public function requestCreateReorderWithAnotherCustomersOrderReference(CartReorderApiTester $I): void |
256
|
|
|
{ |
257
|
|
|
//Arrange |
258
|
|
|
$I->authorizeCustomerToGlue($this->fixtures->getCustomerTransfer()); |
259
|
|
|
|
260
|
|
|
$requestPayload = [ |
261
|
|
|
'data' => [ |
262
|
|
|
'type' => CartReorderRestApiConfig::RESOURCE_CART_REORDER, |
263
|
|
|
'attributes' => [ |
264
|
|
|
'orderReference' => $this->fixtures->getOrderFromAnotherCustomer()->getOrderReferenceOrFail(), |
265
|
|
|
], |
266
|
|
|
], |
267
|
|
|
]; |
268
|
|
|
|
269
|
|
|
// Act |
270
|
|
|
$I->sendPost($I->getCartReorderUrl(), $requestPayload); |
271
|
|
|
|
272
|
|
|
// Assert |
273
|
|
|
$I->seeResponseCodeIs(HttpCode::UNPROCESSABLE_ENTITY); |
274
|
|
|
$I->seeResponseIsJson(); |
275
|
|
|
$I->seeResponseMatchesOpenApiSchema(); |
276
|
|
|
|
277
|
|
|
$errors = $I->getDataFromResponseByJsonPath('$.errors[0]'); |
278
|
|
|
$I->assertEquals($errors[RestCheckoutErrorTransfer::CODE], static::RESPONSE_CODE_ORDER_NOT_FOUND); |
279
|
|
|
$I->assertEquals($errors[RestCheckoutErrorTransfer::STATUS], HttpCode::UNPROCESSABLE_ENTITY); |
280
|
|
|
$I->assertEquals($errors[RestCheckoutErrorTransfer::DETAIL], static::RESPONSE_DETAIL_ORDER_NOT_FOUND); |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* @param \PyzTest\Glue\CartReorder\CartReorderApiTester $I |
285
|
|
|
* |
286
|
|
|
* @return void |
287
|
|
|
*/ |
288
|
|
|
public function requestCreateReorderWithNonExistingReorderStrategy(CartReorderApiTester $I): void |
289
|
|
|
{ |
290
|
|
|
//Arrange |
291
|
|
|
$I->authorizeCustomerToGlue($this->fixtures->getCustomerTransfer()); |
292
|
|
|
|
293
|
|
|
$saveOrderTransfer = $this->fixtures->getOrderWithConcreteProducts(); |
294
|
|
|
$requestPayload = [ |
295
|
|
|
'data' => [ |
296
|
|
|
'type' => CartReorderRestApiConfig::RESOURCE_CART_REORDER, |
297
|
|
|
'attributes' => [ |
298
|
|
|
'orderReference' => $saveOrderTransfer->getOrderReferenceOrFail(), |
299
|
|
|
'reorderStrategy' => 'non-existing-reorder-strategy', |
300
|
|
|
], |
301
|
|
|
], |
302
|
|
|
]; |
303
|
|
|
|
304
|
|
|
// Act |
305
|
|
|
$I->sendPost($I->getCartReorderUrl(), $requestPayload); |
306
|
|
|
|
307
|
|
|
// Assert |
308
|
|
|
$I->seeResponseCodeIs(HttpCode::UNPROCESSABLE_ENTITY); |
309
|
|
|
$I->seeResponseIsJson(); |
310
|
|
|
$I->seeResponseMatchesOpenApiSchema(); |
311
|
|
|
|
312
|
|
|
$errors = $I->getDataFromResponseByJsonPath('$.errors[0]'); |
313
|
|
|
$I->assertEquals($errors[RestCheckoutErrorTransfer::CODE], static::ERROR_CODE_QUOTE_NOT_PROVIDED); |
314
|
|
|
$I->assertEquals($errors[RestCheckoutErrorTransfer::STATUS], HttpCode::UNPROCESSABLE_ENTITY); |
315
|
|
|
$I->assertEquals($errors[RestCheckoutErrorTransfer::DETAIL], static::RESPONSE_DETAIL_QUOTE_NOT_PROVIDED); |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* @param \PyzTest\Glue\CartReorder\CartReorderApiTester $I |
320
|
|
|
* |
321
|
|
|
* @return void |
322
|
|
|
*/ |
323
|
|
|
protected function assertCreateCartReorder(CartReorderApiTester $I): void |
324
|
|
|
{ |
325
|
|
|
$I->seeResponseCodeIs(HttpCode::CREATED); |
326
|
|
|
$I->seeResponseIsJson(); |
327
|
|
|
$I->seeResponseMatchesOpenApiSchema(); |
328
|
|
|
|
329
|
|
|
$I->amSure('The returned resource is of correct type.') |
330
|
|
|
->whenI() |
331
|
|
|
->seeResponseDataContainsSingleResourceOfType(CartReorderApiTester::RESOURCE_CARTS); |
|
|
|
|
332
|
|
|
|
333
|
|
|
$I->amSure('The returned response includes first item.') |
334
|
|
|
->whenI() |
335
|
|
|
->assertResponseContainsItemBySku($this->fixtures->getProductConcreteTransfer1()->getSkuOrFail()); |
336
|
|
|
$I->amSure('The first item has correct quantity.') |
337
|
|
|
->whenI() |
338
|
|
|
->assertItemHasCorrectQuantity($this->fixtures->getProductConcreteTransfer1()->getSkuOrFail(), 2); |
339
|
|
|
|
340
|
|
|
$I->amSure('The returned response includes second item.') |
341
|
|
|
->whenI() |
342
|
|
|
->assertResponseContainsItemBySku($this->fixtures->getProductConcreteTransfer2()->getSkuOrFail()); |
343
|
|
|
$I->amSure('The second item has correct quantity.') |
344
|
|
|
->whenI() |
345
|
|
|
->assertItemHasCorrectQuantity($this->fixtures->getProductConcreteTransfer2()->getSkuOrFail(), 1); |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
/** |
349
|
|
|
* @param \PyzTest\Glue\CartReorder\CartReorderApiTester $I |
350
|
|
|
* |
351
|
|
|
* @return void |
352
|
|
|
*/ |
353
|
|
|
protected function deleteLastResponseCart(CartReorderApiTester $I): void |
354
|
|
|
{ |
355
|
|
|
$I->sendDelete($I->buildCartsUrl($I->getDataFromResponseByJsonPath('$.data.id'))); |
356
|
|
|
} |
357
|
|
|
} |
358
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths