Passed
Pull Request — master (#365)
by Dmitry
21:01
created

requestGuestCartByUuidWithProductConcreteRelationship()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 54
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 36
dl 0
loc 54
c 1
b 0
f 0
rs 9.344
cc 1
nc 1
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
namespace PyzTest\Glue\Carts\RestApi;
9
10
use Codeception\Util\HttpCode;
11
use Generated\Shared\Transfer\CustomerTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\CustomerTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use PyzTest\Glue\Carts\CartsApiTester;
13
use PyzTest\Glue\Carts\RestApi\Fixtures\GuestCartsRestApiFixtures;
14
use Spryker\Glue\CartsRestApi\CartsRestApiConfig;
15
use Spryker\Glue\ProductsRestApi\ProductsRestApiConfig;
16
use Spryker\Shared\Calculation\CalculationPriceMode;
17
18
/**
19
 * Auto-generated group annotations
20
 *
21
 * @group PyzTest
22
 * @group Glue
23
 * @group Carts
24
 * @group RestApi
25
 * @group GuestCartsRestApiCest
26
 * Add your own group annotations below this line
27
 * @group EndToEnd
28
 */
29
class GuestCartsRestApiCest
30
{
31
    /**
32
     * @var \PyzTest\Glue\Carts\RestApi\Fixtures\GuestCartsRestApiFixtures
33
     */
34
    protected GuestCartsRestApiFixtures $fixtures;
35
36
    /**
37
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
38
     *
39
     * @return void
40
     */
41
    public function loadFixtures(CartsApiTester $I): void
42
    {
43
        /** @var \PyzTest\Glue\Carts\RestApi\Fixtures\GuestCartsRestApiFixtures $fixtures */
44
        $fixtures = $I->loadFixtures(GuestCartsRestApiFixtures::class);
45
46
        $this->fixtures = $fixtures;
47
    }
48
49
    /**
50
     * @depends loadFixtures
51
     *
52
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
53
     *
54
     * @return void
55
     */
56
    public function requestGuestCartByUuid(CartsApiTester $I): void
57
    {
58
        // Arrange
59
        $guestCustomerReference = $I->createGuestCustomerReference();
60
        $quoteTransfer = $I->createPersistentQuote(
61
            $I,
62
            (new CustomerTransfer())->setCustomerReference(GuestCartsRestApiFixtures::ANONYMOUS_PREFIX . $guestCustomerReference),
63
            [$this->fixtures->getProductConcreteTransfer1()],
64
        );
65
        $quoteUuid = $quoteTransfer->getUuid();
66
        $url = $I->buildGuestCartUrl($quoteUuid);
67
        $I->haveHttpHeader(
68
            CartsRestApiConfig::HEADER_ANONYMOUS_CUSTOMER_UNIQUE_ID,
69
            $guestCustomerReference,
70
        );
71
72
        // Act
73
        $I->sendGET($url);
74
75
        // Assert
76
        $I->seeResponseCodeIs(HttpCode::OK);
77
        $I->seeResponseIsJson();
78
        $I->seeResponseMatchesOpenApiSchema();
79
80
        $I->amSure('The returned resource is of correct type')
81
            ->whenI()
82
            ->seeResponseDataContainsSingleResourceOfType(CartsRestApiConfig::RESOURCE_GUEST_CARTS);
0 ignored issues
show
Bug introduced by
It seems like seeResponseDataContainsSingleResourceOfType() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

82
            ->/** @scrutinizer ignore-call */ seeResponseDataContainsSingleResourceOfType(CartsRestApiConfig::RESOURCE_GUEST_CARTS);
Loading history...
83
84
        $I->amSure('The returned resource has correct id')
85
            ->whenI()
86
            ->seeSingleResourceIdEqualTo($quoteUuid);
0 ignored issues
show
Bug introduced by
It seems like seeSingleResourceIdEqualTo() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

86
            ->/** @scrutinizer ignore-call */ seeSingleResourceIdEqualTo($quoteUuid);
Loading history...
87
88
        $I->amSure('The returned resource has correct self-link')
89
            ->whenI()
90
            ->seeSingleResourceHasSelfLink($url);
0 ignored issues
show
Bug introduced by
It seems like seeSingleResourceHasSelfLink() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

90
            ->/** @scrutinizer ignore-call */ seeSingleResourceHasSelfLink($url);
Loading history...
91
    }
92
93
    /**
94
     * @depends loadFixtures
95
     *
96
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
97
     *
98
     * @return void
99
     */
100
    public function requestGuestCarts(CartsApiTester $I): void
101
    {
102
        // Arrange
103
        $guestCustomerReference = $I->createGuestCustomerReference();
104
        $quoteTransfer = $I->createPersistentQuote(
105
            $I,
106
            (new CustomerTransfer())->setCustomerReference(GuestCartsRestApiFixtures::ANONYMOUS_PREFIX . $guestCustomerReference),
107
            [$this->fixtures->getProductConcreteTransfer1()],
108
        );
109
        $quoteUuid = $quoteTransfer->getUuid();
110
        $I->haveHttpHeader(
111
            CartsRestApiConfig::HEADER_ANONYMOUS_CUSTOMER_UNIQUE_ID,
112
            $guestCustomerReference,
113
        );
114
115
        // Act
116
        $I->sendGET($I->buildGuestCartsUrl());
117
118
        // Assert
119
        $I->seeResponseCodeIs(HttpCode::OK);
120
        $I->seeResponseIsJson();
121
        $I->seeResponseMatchesOpenApiSchema();
122
123
        $I->amSure('Response data contains resource collection')
124
            ->whenI()
125
            ->seeResponseDataContainsResourceCollectionOfType(CartsRestApiConfig::RESOURCE_GUEST_CARTS);
0 ignored issues
show
Bug introduced by
It seems like seeResponseDataContainsResourceCollectionOfType() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

125
            ->/** @scrutinizer ignore-call */ seeResponseDataContainsResourceCollectionOfType(CartsRestApiConfig::RESOURCE_GUEST_CARTS);
Loading history...
126
127
        $I->amSure('Resource collection has resource')
128
            ->whenI()
129
            ->seeResourceCollectionHasResourceWithId($quoteUuid);
0 ignored issues
show
Bug introduced by
It seems like seeResourceCollectionHasResourceWithId() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

129
            ->/** @scrutinizer ignore-call */ seeResourceCollectionHasResourceWithId($quoteUuid);
Loading history...
130
131
        $I->amSure('Resource has correct self-link')
132
            ->whenI()
133
            ->seeResourceByIdHasSelfLink($quoteUuid, $I->buildGuestCartUrl($quoteUuid));
0 ignored issues
show
Bug introduced by
It seems like seeResourceByIdHasSelfLink() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

133
            ->/** @scrutinizer ignore-call */ seeResourceByIdHasSelfLink($quoteUuid, $I->buildGuestCartUrl($quoteUuid));
Loading history...
134
    }
135
136
    /**
137
     * @depends loadFixtures
138
     *
139
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
140
     *
141
     * @return void
142
     */
143
    public function requestGuestCartByUuidWithGuestCartItemsRelationship(CartsApiTester $I): void
144
    {
145
        // Arrange
146
        $guestCustomerReference = $I->createGuestCustomerReference();
147
        $quoteTransfer = $I->createPersistentQuote(
148
            $I,
149
            (new CustomerTransfer())->setCustomerReference(GuestCartsRestApiFixtures::ANONYMOUS_PREFIX . $guestCustomerReference),
150
            [$this->fixtures->getProductConcreteTransfer1()],
151
        );
152
        $quoteUuid = $quoteTransfer->getUuid();
153
        $guestCartItemGroupKey = $quoteTransfer->getItems()->offsetGet(0)->getGroupKey();
154
        $I->haveHttpHeader(
155
            CartsRestApiConfig::HEADER_ANONYMOUS_CUSTOMER_UNIQUE_ID,
156
            $guestCustomerReference,
157
        );
158
        $url = $I->buildGuestCartUrl(
159
            $quoteUuid,
160
            [
161
                CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
162
            ],
163
        );
164
165
        // Act
166
        $I->sendGET($url);
167
168
        // Assert
169
        $I->seeResponseCodeIs(HttpCode::OK);
170
        $I->seeResponseIsJson();
171
        $I->seeResponseMatchesOpenApiSchema();
172
173
        $I->amSure('The returned resource has relationship')
174
            ->whenI()
175
            ->seeSingleResourceHasRelationshipByTypeAndId(
0 ignored issues
show
Bug introduced by
It seems like seeSingleResourceHasRelationshipByTypeAndId() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

175
            ->/** @scrutinizer ignore-call */ seeSingleResourceHasRelationshipByTypeAndId(
Loading history...
176
                CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
177
                $guestCartItemGroupKey,
178
            );
179
180
        $I->amSure('The returned resource has include')
181
            ->whenI()
182
            ->seeIncludesContainsResourceByTypeAndId(
0 ignored issues
show
Bug introduced by
It seems like seeIncludesContainsResourceByTypeAndId() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

182
            ->/** @scrutinizer ignore-call */ seeIncludesContainsResourceByTypeAndId(
Loading history...
183
                CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
184
                $guestCartItemGroupKey,
185
            );
186
187
        $I->amSure('The include has correct self-link')
188
            ->whenI()
189
            ->seeIncludedResourceByTypeAndIdHasSelfLink(
0 ignored issues
show
Bug introduced by
It seems like seeIncludedResourceByTypeAndIdHasSelfLink() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

189
            ->/** @scrutinizer ignore-call */ seeIncludedResourceByTypeAndIdHasSelfLink(
Loading history...
190
                CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
191
                $guestCartItemGroupKey,
192
                $I->buildGuestCartItemUrl($quoteUuid, $guestCartItemGroupKey),
193
            );
194
    }
195
196
    /**
197
     * @depends loadFixtures
198
     *
199
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
200
     *
201
     * @return void
202
     */
203
    public function requestGuestCartByUuidWithProductConcreteRelationship(CartsApiTester $I): void
204
    {
205
        // Arrange
206
        $guestCustomerReference = $I->createGuestCustomerReference();
207
        $quoteTransfer = $I->createPersistentQuote(
208
            $I,
209
            (new CustomerTransfer())->setCustomerReference(GuestCartsRestApiFixtures::ANONYMOUS_PREFIX . $guestCustomerReference),
210
            [$this->fixtures->getProductConcreteTransfer1()],
211
        );
212
213
        $guestCartItemGroupKey = $quoteTransfer->getItems()->offsetGet(0)->getGroupKey();
214
        $productConcreteSku = $this->fixtures->getProductConcreteTransfer1()->getSku();
215
        $url = $I->buildGuestCartUrl(
216
            $quoteTransfer->getUuid(),
217
            [
218
                CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
219
                ProductsRestApiConfig::RESOURCE_CONCRETE_PRODUCTS,
220
            ],
221
        );
222
        $I->haveHttpHeader(
223
            CartsRestApiConfig::HEADER_ANONYMOUS_CUSTOMER_UNIQUE_ID,
224
            $guestCustomerReference,
225
        );
226
227
        // Act
228
        $I->sendGET($url);
229
230
        // Assert
231
        $I->seeResponseCodeIs(HttpCode::OK);
232
        $I->seeResponseIsJson();
233
        $I->seeResponseMatchesOpenApiSchema();
234
235
        $I->amSure('The included resource has a relationship')
236
            ->whenI()
237
            ->seeIncludedResourceByTypeAndIdHasRelationshipByTypeAndId(
0 ignored issues
show
Bug introduced by
It seems like seeIncludedResourceByTyp...lationshipByTypeAndId() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

237
            ->/** @scrutinizer ignore-call */ seeIncludedResourceByTypeAndIdHasRelationshipByTypeAndId(
Loading history...
238
                CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
239
                $guestCartItemGroupKey,
240
                ProductsRestApiConfig::RESOURCE_CONCRETE_PRODUCTS,
241
                $productConcreteSku,
242
            );
243
244
        $I->amSure('The returned resource has include')
245
            ->whenI()
246
            ->seeIncludesContainsResourceByTypeAndId(
247
                ProductsRestApiConfig::RESOURCE_CONCRETE_PRODUCTS,
248
                $productConcreteSku,
249
            );
250
251
        $I->amSure('The include has correct self-link')
252
            ->whenI()
253
            ->seeIncludedResourceByTypeAndIdHasSelfLink(
254
                ProductsRestApiConfig::RESOURCE_CONCRETE_PRODUCTS,
255
                $productConcreteSku,
256
                $I->buildProductConcreteUrl($productConcreteSku),
257
            );
258
    }
259
260
    /**
261
     * @depends loadFixtures
262
     *
263
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
264
     *
265
     * @return void
266
     */
267
    public function requestGuestCartByNotExistingGuestCartUuid(CartsApiTester $I): void
268
    {
269
        // Arrange
270
        $I->haveHttpHeader(
271
            CartsRestApiConfig::HEADER_ANONYMOUS_CUSTOMER_UNIQUE_ID,
272
            'NotExistingReference',
273
        );
274
275
        // Act
276
        $I->sendGET($I->buildGuestCartUrl('NotExistingUuid'));
277
278
        // Assert
279
        $I->seeResponseCodeIs(HttpCode::NOT_FOUND);
280
        $I->seeResponseIsJson();
281
        $I->seeResponseMatchesOpenApiSchema();
282
    }
283
284
    /**
285
     * @depends loadFixtures
286
     *
287
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
288
     *
289
     * @return void
290
     */
291
    public function requestCreateGuestCart(CartsApiTester $I): void
292
    {
293
        // Arrange
294
        $I->haveHttpHeader(CartsRestApiConfig::HEADER_ANONYMOUS_CUSTOMER_UNIQUE_ID, uniqid(123, true));
295
296
        // Act
297
        $I->sendPOST(
298
            CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
299
            [
300
                'data' => [
301
                    'type' => CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
302
                    'attributes' => [
303
                        'sku' => $this->fixtures->getProductConcreteTransfer1()->getSku(),
304
                        'quantity' => 1,
305
                    ],
306
                ],
307
            ],
308
        );
309
310
        // Assert
311
        $I->seeResponseCodeIs(HttpCode::CREATED);
312
        $I->seeResponseIsJson();
313
314
        $I->amSure('Returned resource is of type guest-carts')
315
            ->whenI()
316
            ->seeResponseDataContainsSingleResourceOfType(CartsRestApiConfig::RESOURCE_GUEST_CARTS);
317
318
        $I->seeSingleResourceHasSelfLink(
319
            $I->formatFullUrl(
320
                '{resourceGuestCarts}/{guestCartUuid}',
321
                [
322
                    'resourceGuestCarts' => CartsRestApiConfig::RESOURCE_GUEST_CARTS,
323
                    'guestCartUuid' => $I->getDataFromResponseByJsonPath('$.data')['id'],
324
                ],
325
            ),
326
        );
327
    }
328
329
    /**
330
     * @depends loadFixtures
331
     *
332
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
333
     *
334
     * @return void
335
     */
336
    public function requestCreateGuestCartWithoutAnonymousCustomerUniqueId(CartsApiTester $I): void
337
    {
338
        // Act
339
        $I->sendPOST(
340
            CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
341
            [
342
                'data' => [
343
                    'type' => CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
344
                    'attributes' => [
345
                        'sku' => $this->fixtures->getProductConcreteTransfer1()->getSku(),
346
                        'quantity' => 1,
347
                    ],
348
                ],
349
            ],
350
        );
351
352
        // Assert
353
        $I->seeResponseCodeIs(HttpCode::BAD_REQUEST);
354
        $I->seeResponseIsJson();
355
    }
356
357
    /**
358
     * @depends loadFixtures
359
     *
360
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
361
     *
362
     * @return void
363
     */
364
    public function requestCreateGuestCartWithoutSku(CartsApiTester $I): void
365
    {
366
        // Arrange
367
        $I->haveHttpHeader(
368
            CartsRestApiConfig::HEADER_ANONYMOUS_CUSTOMER_UNIQUE_ID,
369
            $I->createGuestCustomerReference(),
370
        );
371
372
        // Act
373
        $I->sendPOST(
374
            CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
375
            [
376
                'data' => [
377
                    'type' => CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
378
                    'attributes' => [
379
                        'quantity' => 1,
380
                    ],
381
                ],
382
            ],
383
        );
384
385
        // Assert
386
        $I->seeResponseCodeIs(HttpCode::UNPROCESSABLE_ENTITY);
387
        $I->seeResponseIsJson();
388
    }
389
390
    /**
391
     * @depends loadFixtures
392
     *
393
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
394
     *
395
     * @return void
396
     */
397
    public function requestCreateGuestCartWithoutQuantity(CartsApiTester $I): void
398
    {
399
        // Arrange
400
        $I->haveHttpHeader(
401
            CartsRestApiConfig::HEADER_ANONYMOUS_CUSTOMER_UNIQUE_ID,
402
            $I->createGuestCustomerReference(),
403
        );
404
405
        // Act
406
        $I->sendPOST(
407
            CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
408
            [
409
                'data' => [
410
                    'type' => CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
411
                    'attributes' => [
412
                        'sku' => $this->fixtures->getProductConcreteTransfer1()->getSku(),
413
                    ],
414
                ],
415
            ],
416
        );
417
418
        // Assert
419
        $I->seeResponseCodeIs(HttpCode::UNPROCESSABLE_ENTITY);
420
        $I->seeResponseIsJson();
421
    }
422
423
    /**
424
     * @depends loadFixtures
425
     *
426
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
427
     *
428
     * @return void
429
     */
430
    public function requestGetGuestCartWithoutAnonymousCustomerUniqueId(CartsApiTester $I): void
431
    {
432
        // Act
433
        $I->sendGET(
434
            $I->formatUrl(
435
                '{resourceGuestCarts}',
436
                [
437
                    'resourceGuestCarts' => CartsRestApiConfig::RESOURCE_GUEST_CARTS,
438
                ],
439
            ),
440
        );
441
442
        // Assert
443
        $I->seeResponseCodeIs(HttpCode::BAD_REQUEST);
444
        $I->seeResponseIsJson();
445
    }
446
447
    /**
448
     * @depends loadFixtures
449
     *
450
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
451
     *
452
     * @return void
453
     */
454
    public function requestUpdateGuestCart(CartsApiTester $I): void
455
    {
456
        // Arrange
457
        $guestCustomerReference = $I->createGuestCustomerReference();
458
        $I->haveHttpHeader(
459
            CartsRestApiConfig::HEADER_ANONYMOUS_CUSTOMER_UNIQUE_ID,
460
            $guestCustomerReference,
461
        );
462
        $quoteTransfer = $I->createPersistentQuote(
463
            $I,
464
            (new CustomerTransfer())->setCustomerReference(GuestCartsRestApiFixtures::ANONYMOUS_PREFIX . $guestCustomerReference),
465
            [],
466
        );
467
        $guestQuoteUuid = $quoteTransfer->getUuid();
468
        $formattedUrl = $I->formatUrl(
469
            '{resourceGuestCarts}/{guestCartUuid}',
470
            [
471
                'resourceGuestCarts' => CartsRestApiConfig::RESOURCE_GUEST_CARTS,
472
                'guestCartUuid' => $guestQuoteUuid,
473
            ],
474
        );
475
476
        // Act
477
        $I->sendPATCH(
478
            $formattedUrl,
479
            [
480
                'data' => [
481
                    'type' => CartsRestApiConfig::RESOURCE_GUEST_CARTS,
482
                    'attributes' => [
483
                        'name' => $this->fixtures::TEST_GUEST_CART_NAME,
484
                        'currency' => $this->fixtures::CURRENCY_EUR,
485
                        'priceMode' => CalculationPriceMode::PRICE_MODE_GROSS,
486
                    ],
487
                ],
488
            ],
489
        );
490
491
        // Assert
492
        $I->seeResponseCodeIs(HttpCode::OK);
493
        $I->seeResponseMatchesOpenApiSchema();
494
495
        $I->amSure('Returned resource has correct id')
496
            ->whenI()
497
            ->seeSingleResourceIdEqualTo($guestQuoteUuid);
498
499
        $I->amSure(sprintf('Returned resource is of type %s', CartsRestApiConfig::RESOURCE_GUEST_CARTS))
500
            ->whenI()
501
            ->seeResponseDataContainsSingleResourceOfType(CartsRestApiConfig::RESOURCE_GUEST_CARTS);
502
503
        $I->seeSingleResourceHasSelfLink(
504
            $I->formatFullUrl(
505
                '{resourceGuestCarts}/{guestCartUuid}',
506
                [
507
                    'resourceGuestCarts' => CartsRestApiConfig::RESOURCE_GUEST_CARTS,
508
                    'guestCartUuid' => $guestQuoteUuid,
509
                ],
510
            ),
511
        );
512
    }
513
514
    /**
515
     * @depends loadFixtures
516
     *
517
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
518
     *
519
     * @return void
520
     */
521
    public function requestUpdatePriceModeOfNonEmptyGuestCart(CartsApiTester $I): void
522
    {
523
        // Arrange
524
        $guestCustomerReference = $I->createGuestCustomerReference();
525
        $quoteTransfer = $I->createPersistentQuote(
526
            $I,
527
            (new CustomerTransfer())->setCustomerReference(GuestCartsRestApiFixtures::ANONYMOUS_PREFIX . $guestCustomerReference),
528
            [$this->fixtures->getProductConcreteTransfer1()],
529
        );
530
        $guestQuoteUuid = $quoteTransfer->getUuid();
531
532
        $I->haveHttpHeader(
533
            CartsRestApiConfig::HEADER_ANONYMOUS_CUSTOMER_UNIQUE_ID,
534
            $guestCustomerReference,
535
        );
536
537
        // Act
538
        $I->sendPATCH(
539
            $I->formatUrl(
540
                '{resourceGuestCarts}/{guestCartUuid}',
541
                [
542
                    'resourceGuestCarts' => CartsRestApiConfig::RESOURCE_GUEST_CARTS,
543
                    'guestCartUuid' => $guestQuoteUuid,
544
                ],
545
            ),
546
            [
547
                'data' => [
548
                    'type' => CartsRestApiConfig::RESOURCE_GUEST_CARTS,
549
                    'attributes' => [
550
                        'name' => $this->fixtures::TEST_GUEST_CART_NAME,
551
                        'currency' => $this->fixtures::CURRENCY_EUR,
552
                        'priceMode' => CalculationPriceMode::PRICE_MODE_NET,
553
                    ],
554
                ],
555
            ],
556
        );
557
558
        // Assert
559
        $I->seeResponseCodeIs(HttpCode::UNPROCESSABLE_ENTITY);
560
        $I->seeResponseMatchesOpenApiSchema();
561
    }
562
563
    /**
564
     * @depends loadFixtures
565
     *
566
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
567
     *
568
     * @return void
569
     */
570
    public function requestUpdateGuestCartWithoutGuestCartUuid(CartsApiTester $I): void
571
    {
572
        // Arrange
573
        $I->haveHttpHeader(
574
            CartsRestApiConfig::HEADER_ANONYMOUS_CUSTOMER_UNIQUE_ID,
575
            $I->createGuestCustomerReference(),
576
        );
577
578
        // Act
579
        $I->sendPATCH(
580
            CartsRestApiConfig::RESOURCE_GUEST_CARTS,
581
            [
582
                'data' => [
583
                    'type' => CartsRestApiConfig::RESOURCE_GUEST_CARTS,
584
                    'attributes' => [
585
                        'name' => $this->fixtures::TEST_GUEST_CART_NAME,
586
                        'currency' => $this->fixtures::CURRENCY_EUR,
587
                        'priceMode' => CalculationPriceMode::PRICE_MODE_GROSS,
588
                    ],
589
                ],
590
            ],
591
        );
592
593
        // Assert
594
        $I->seeResponseCodeIs(HttpCode::BAD_REQUEST);
595
        $I->seeResponseIsJson();
596
    }
597
598
    /**
599
     * @depends loadFixtures
600
     *
601
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
602
     *
603
     * @return void
604
     */
605
    public function requestUpdateGuestCartWithoutAnonymousCustomerUniqueId(CartsApiTester $I): void
606
    {
607
        // Arrange
608
        $quoteTransfer = $I->createPersistentQuote(
609
            $I,
610
            (new CustomerTransfer())->setCustomerReference(GuestCartsRestApiFixtures::ANONYMOUS_PREFIX . $I->createGuestCustomerReference()),
611
            [$this->fixtures->getProductConcreteTransfer1()],
612
        );
613
        $guestQuoteUuid = $quoteTransfer->getUuid();
614
615
        // Act
616
        $I->sendPATCH(
617
            $I->formatUrl(
618
                '{resourceGuestCarts}/{guestCartUuid}',
619
                [
620
                    'resourceGuestCarts' => CartsRestApiConfig::RESOURCE_GUEST_CARTS,
621
                    'guestCartUuid' => $guestQuoteUuid,
622
                ],
623
            ),
624
            [
625
                'data' => [
626
                    'type' => CartsRestApiConfig::RESOURCE_GUEST_CARTS,
627
                    'attributes' => [
628
                        'name' => $this->fixtures::TEST_GUEST_CART_NAME,
629
                        'currency' => $this->fixtures::CURRENCY_EUR,
630
                        'priceMode' => CalculationPriceMode::PRICE_MODE_GROSS,
631
                    ],
632
                ],
633
            ],
634
        );
635
636
        // Assert
637
        $I->seeResponseCodeIs(HttpCode::BAD_REQUEST);
638
        $I->seeResponseIsJson();
639
    }
640
641
    /**
642
     * @depends loadFixtures
643
     *
644
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
645
     *
646
     * @return void
647
     */
648
    public function requestAddItemsToGuestCart(CartsApiTester $I): void
649
    {
650
        // Arrange
651
        $guestCustomerReference = $I->createGuestCustomerReference();
652
        $I->haveHttpHeader(
653
            CartsRestApiConfig::HEADER_ANONYMOUS_CUSTOMER_UNIQUE_ID,
654
            $guestCustomerReference,
655
        );
656
        $quoteTransfer = $I->createPersistentQuote(
657
            $I,
658
            (new CustomerTransfer())->setCustomerReference(GuestCartsRestApiFixtures::ANONYMOUS_PREFIX . $guestCustomerReference),
659
            [],
660
        );
661
        $guestQuoteUuid = $quoteTransfer->getUuid();
662
663
        // Act
664
        $I->sendPOST(
665
            $I->formatUrl(
666
                '{resourceGuestCarts}/{guestCartUuid}/{resourceGuestCartItems}',
667
                [
668
                    'resourceGuestCarts' => CartsRestApiConfig::RESOURCE_GUEST_CARTS,
669
                    'guestCartUuid' => $guestQuoteUuid,
670
                    'resourceGuestCartItems' => CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
671
                ],
672
            ),
673
            [
674
                'data' => [
675
                    'type' => CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
676
                    'attributes' => [
677
                        'sku' => $this->fixtures->getProductConcreteTransfer1()->getSku(),
678
                        'quantity' => 1,
679
                    ],
680
                ],
681
            ],
682
        );
683
684
        // Assert
685
        $I->seeResponseCodeIs(HttpCode::CREATED);
686
        $I->seeResponseMatchesOpenApiSchema();
687
688
        $I->amSure('Returned resource has correct id')
689
            ->whenI()
690
            ->seeSingleResourceIdEqualTo($guestQuoteUuid);
691
692
        $I->amSure(sprintf('Returned resource is of type %s', CartsRestApiConfig::RESOURCE_GUEST_CARTS))
693
            ->whenI()
694
            ->seeResponseDataContainsSingleResourceOfType(CartsRestApiConfig::RESOURCE_GUEST_CARTS);
695
696
        $I->seeSingleResourceHasSelfLink(
697
            $I->formatFullUrl(
698
                '{resourceGuestCarts}/{guestCartUuid}',
699
                [
700
                    'resourceGuestCarts' => CartsRestApiConfig::RESOURCE_GUEST_CARTS,
701
                    'guestCartUuid' => $guestQuoteUuid,
702
                ],
703
            ),
704
        );
705
    }
706
707
    /**
708
     * @depends loadFixtures
709
     *
710
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
711
     *
712
     * @return void
713
     */
714
    public function requestAddItemsToGuestCartWithoutAnonymousCustomerUniqueId(CartsApiTester $I): void
715
    {
716
        // Arrange
717
        $quoteTransfer = $I->createPersistentQuote(
718
            $I,
719
            (new CustomerTransfer())->setCustomerReference(GuestCartsRestApiFixtures::ANONYMOUS_PREFIX . $I->createGuestCustomerReference()),
720
            [],
721
        );
722
        $guestQuoteUuid = $quoteTransfer->getUuid();
723
724
        // Act
725
        $I->sendPOST(
726
            $I->formatUrl(
727
                '{resourceGuestCarts}/{guestCartUuid}/{resourceGuestCartItems}',
728
                [
729
                    'resourceGuestCarts' => CartsRestApiConfig::RESOURCE_GUEST_CARTS,
730
                    'guestCartUuid' => $guestQuoteUuid,
731
                    'resourceGuestCartItems' => CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
732
                ],
733
            ),
734
            [
735
                'data' => [
736
                    'type' => CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
737
                    'attributes' => [
738
                        'sku' => $this->fixtures->getProductConcreteTransfer2()->getSku(),
739
                        'quantity' => 1,
740
                    ],
741
                ],
742
            ],
743
        );
744
745
        // Assert
746
        $I->seeResponseCodeIs(HttpCode::BAD_REQUEST);
747
        $I->seeResponseIsJson();
748
    }
749
750
    /**
751
     * @depends loadFixtures
752
     *
753
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
754
     *
755
     * @return void
756
     */
757
    public function requestAddItemsToGuestCartWithoutItemSku(CartsApiTester $I): void
758
    {
759
        // Arrange
760
        $guestCustomerReference = $I->createGuestCustomerReference();
761
        $quoteTransfer = $I->createPersistentQuote(
762
            $I,
763
            (new CustomerTransfer())->setCustomerReference(GuestCartsRestApiFixtures::ANONYMOUS_PREFIX . $guestCustomerReference),
764
            [$this->fixtures->getProductConcreteTransfer1()],
765
        );
766
        $guestQuoteUuid = $quoteTransfer->getUuid();
767
768
        $I->haveHttpHeader(
769
            CartsRestApiConfig::HEADER_ANONYMOUS_CUSTOMER_UNIQUE_ID,
770
            $guestCustomerReference,
771
        );
772
773
        // Act
774
        $I->sendPOST(
775
            $I->formatUrl(
776
                '{resourceGuestCarts}/{guestCartUuid}/{resourceGuestCartItems}',
777
                [
778
                    'resourceGuestCarts' => CartsRestApiConfig::RESOURCE_GUEST_CARTS,
779
                    'guestCartUuid' => $guestQuoteUuid,
780
                    'resourceGuestCartItems' => CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
781
                ],
782
            ),
783
            [
784
                'data' => [
785
                    'type' => CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
786
                    'attributes' => [
787
                        'quantity' => 1,
788
                    ],
789
                ],
790
            ],
791
        );
792
793
        // Assert
794
        $I->seeResponseCodeIs(HttpCode::UNPROCESSABLE_ENTITY);
795
        $I->seeResponseIsJson();
796
    }
797
798
    /**
799
     * @depends loadFixtures
800
     *
801
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
802
     *
803
     * @return void
804
     */
805
    public function requestAddItemsToGuestCartWithoutItemQuantity(CartsApiTester $I): void
806
    {
807
        // Arrange
808
        $guestCustomerReference = $I->createGuestCustomerReference();
809
        $quoteTransfer = $I->createPersistentQuote(
810
            $I,
811
            (new CustomerTransfer())->setCustomerReference(GuestCartsRestApiFixtures::ANONYMOUS_PREFIX . $guestCustomerReference),
812
            [$this->fixtures->getProductConcreteTransfer1()],
813
        );
814
        $guestQuoteUuid = $quoteTransfer->getUuid();
815
        $I->haveHttpHeader(
816
            CartsRestApiConfig::HEADER_ANONYMOUS_CUSTOMER_UNIQUE_ID,
817
            $guestCustomerReference,
818
        );
819
820
        // Act
821
        $I->sendPOST(
822
            $I->formatUrl(
823
                '{resourceGuestCarts}/{guestCartUuid}/{resourceGuestCartItems}',
824
                [
825
                    'resourceGuestCarts' => CartsRestApiConfig::RESOURCE_GUEST_CARTS,
826
                    'guestCartUuid' => $guestQuoteUuid,
827
                    'resourceGuestCartItems' => CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
828
                ],
829
            ),
830
            [
831
                'data' => [
832
                    'type' => CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
833
                    'attributes' => [
834
                        'sku' => $this->fixtures->getProductConcreteTransfer2()->getSku(),
835
                    ],
836
                ],
837
            ],
838
        );
839
840
        // Assert
841
        $I->seeResponseCodeIs(HttpCode::UNPROCESSABLE_ENTITY);
842
        $I->seeResponseMatchesOpenApiSchema();
843
    }
844
845
    /**
846
     * @depends loadFixtures
847
     *
848
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
849
     *
850
     * @return void
851
     */
852
    public function requestUpdateItemsInGuestCart(CartsApiTester $I): void
853
    {
854
        // Arrange
855
        $guestCustomerReference = $I->createGuestCustomerReference();
856
        $I->haveHttpHeader(
857
            CartsRestApiConfig::HEADER_ANONYMOUS_CUSTOMER_UNIQUE_ID,
858
            $guestCustomerReference,
859
        );
860
        $quoteTransfer = $I->createPersistentQuote(
861
            $I,
862
            (new CustomerTransfer())->setCustomerReference(GuestCartsRestApiFixtures::ANONYMOUS_PREFIX . $guestCustomerReference),
863
            [$this->fixtures->getProductConcreteTransfer1()],
864
        );
865
        $guestQuoteUuid = $quoteTransfer->getUuid();
866
        $itemGroupKey = $I->getGroupKeyFromQuote($quoteTransfer, $this->fixtures->getProductConcreteTransfer1()->getSku());
867
868
        // Act
869
        $I->sendPATCH(
870
            $I->formatUrl(
871
                '{resourceGuestCarts}/{guestCartUuid}/{resourceGuestCartItems}/{itemId}?include={resourceGuestCartItems}',
872
                [
873
                    'resourceGuestCarts' => CartsRestApiConfig::RESOURCE_GUEST_CARTS,
874
                    'guestCartUuid' => $guestQuoteUuid,
875
                    'resourceGuestCartItems' => CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
876
                    'itemId' => $itemGroupKey,
877
                ],
878
            ),
879
            [
880
                'data' => [
881
                    'type' => CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
882
                    'attributes' => [
883
                        'quantity' => $this->fixtures::QUANTITY_FOR_ITEM_UPDATE,
884
                    ],
885
                ],
886
            ],
887
        );
888
889
        // Assert
890
        $I->seeResponseCodeIs(HttpCode::OK);
891
        $I->seeResponseMatchesOpenApiSchema();
892
893
        $I->amSure('Returned resource has correct id')
894
            ->whenI()
895
            ->seeSingleResourceIdEqualTo($guestQuoteUuid);
896
897
        $I->seeCartItemQuantityEqualsToQuantityInRequest(
898
            $this->fixtures::QUANTITY_FOR_ITEM_UPDATE,
899
            CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
900
            $itemGroupKey,
0 ignored issues
show
Bug introduced by
It seems like $itemGroupKey can also be of type null; however, parameter $itemSku of PyzTest\Glue\Carts\Carts...lsToQuantityInRequest() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

900
            /** @scrutinizer ignore-type */ $itemGroupKey,
Loading history...
901
        );
902
903
        $I->seeSingleResourceHasSelfLink(
904
            $I->formatFullUrl(
905
                '{resourceGuestCarts}/{guestCartUuid}',
906
                [
907
                    'resourceGuestCarts' => CartsRestApiConfig::RESOURCE_GUEST_CARTS,
908
                    'guestCartUuid' => $guestQuoteUuid,
909
                ],
910
            ),
911
        );
912
    }
913
914
    /**
915
     * @depends loadFixtures
916
     *
917
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
918
     *
919
     * @return void
920
     */
921
    public function requestUpdateItemsInGuestCartWithoutGuestCartUuid(CartsApiTester $I): void
922
    {
923
        // Arrange
924
        $I->haveHttpHeader(
925
            CartsRestApiConfig::HEADER_ANONYMOUS_CUSTOMER_UNIQUE_ID,
926
            $I->createGuestCustomerReference(),
927
        );
928
929
        // Act
930
        $I->sendPATCH(
931
            $I->formatUrl(
932
                '{resourceGuestCarts}//{resourceGuestCartItems}/{guestCartItemSku}',
933
                [
934
                    'resourceGuestCarts' => CartsRestApiConfig::RESOURCE_GUEST_CARTS,
935
                    'resourceGuestCartItems' => CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
936
                    'guestCartItemSku' => $this->fixtures->getProductConcreteTransfer2()->getSku(),
937
                ],
938
            ),
939
            [
940
                'data' => [
941
                    'type' => CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
942
                    'attributes' => [
943
                        'quantity' => $this->fixtures::QUANTITY_FOR_ITEM_UPDATE,
944
                    ],
945
                ],
946
            ],
947
        );
948
949
        // Assert
950
        $I->seeResponseCodeIs(HttpCode::BAD_REQUEST);
951
        $I->seeResponseIsJson();
952
    }
953
954
    /**
955
     * @depends loadFixtures
956
     *
957
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
958
     *
959
     * @return void
960
     */
961
    public function requestUpdateItemsInGuestCartWithoutAnonymousCustomerUniqueId(CartsApiTester $I): void
962
    {
963
        // Arrange
964
        $quoteTransfer = $I->createPersistentQuote(
965
            $I,
966
            (new CustomerTransfer())->setCustomerReference(GuestCartsRestApiFixtures::ANONYMOUS_PREFIX . $I->createGuestCustomerReference()),
967
            [$this->fixtures->getProductConcreteTransfer1()],
968
        );
969
        $guestQuoteUuid = $quoteTransfer->getUuid();
970
971
        // Act
972
        $I->sendPATCH(
973
            $I->formatUrl(
974
                '{resourceGuestCarts}/{guestCartUuid}/{resourceGuestCartItems}/{itemSku}',
975
                [
976
                    'resourceGuestCarts' => CartsRestApiConfig::RESOURCE_GUEST_CARTS,
977
                    'guestCartUuid' => $guestQuoteUuid,
978
                    'resourceGuestCartItems' => CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
979
                    'itemSku' => $this->fixtures->getProductConcreteTransfer1()->getSku(),
980
                ],
981
            ),
982
            [
983
                'data' => [
984
                    'type' => CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
985
                    'attributes' => [
986
                        'quantity' => $this->fixtures::QUANTITY_FOR_ITEM_UPDATE,
987
                    ],
988
                ],
989
            ],
990
        );
991
992
        // Assert
993
        $I->seeResponseCodeIs(HttpCode::BAD_REQUEST);
994
        $I->seeResponseIsJson();
995
    }
996
997
    /**
998
     * @depends loadFixtures
999
     *
1000
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
1001
     *
1002
     * @return void
1003
     */
1004
    public function requestUpdateItemsInGuestCartWithoutQuantity(CartsApiTester $I): void
1005
    {
1006
        // Arrange
1007
        $guestCustomerReference = $I->createGuestCustomerReference();
1008
        $quoteTransfer = $I->createPersistentQuote(
1009
            $I,
1010
            (new CustomerTransfer())->setCustomerReference(GuestCartsRestApiFixtures::ANONYMOUS_PREFIX . $guestCustomerReference),
1011
            [$this->fixtures->getProductConcreteTransfer1()],
1012
        );
1013
        $guestQuoteUuid = $quoteTransfer->getUuid();
1014
        $I->haveHttpHeader(
1015
            CartsRestApiConfig::HEADER_ANONYMOUS_CUSTOMER_UNIQUE_ID,
1016
            $guestCustomerReference,
1017
        );
1018
1019
        // Act
1020
        $I->sendPATCH(
1021
            $I->formatUrl(
1022
                '{resourceGuestCarts}/{guestCartUuid}/{resourceGuestCartItems}/{itemSku}',
1023
                [
1024
                    'resourceGuestCarts' => CartsRestApiConfig::RESOURCE_GUEST_CARTS,
1025
                    'guestCartUuid' => $guestQuoteUuid,
1026
                    'resourceGuestCartItems' => CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
1027
                    'itemSku' => $this->fixtures->getProductConcreteTransfer1()->getSku(),
1028
                ],
1029
            ),
1030
            [
1031
                'data' => [
1032
                    'type' => CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
1033
                    'attributes' => [
1034
                    ],
1035
                ],
1036
            ],
1037
        );
1038
1039
        // Assert
1040
        $I->seeResponseCodeIs(HttpCode::UNPROCESSABLE_ENTITY);
1041
        $I->seeResponseMatchesOpenApiSchema();
1042
    }
1043
1044
    /**
1045
     * @depends loadFixtures
1046
     *
1047
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
1048
     *
1049
     * @return void
1050
     */
1051
    public function requestUpdateItemsInGuestCartWithoutItemSku(CartsApiTester $I): void
1052
    {
1053
        // Arrange
1054
        $guestCustomerReference = $I->createGuestCustomerReference();
1055
        $quoteTransfer = $I->createPersistentQuote(
1056
            $I,
1057
            (new CustomerTransfer())->setCustomerReference(GuestCartsRestApiFixtures::ANONYMOUS_PREFIX . $guestCustomerReference),
1058
            [$this->fixtures->getProductConcreteTransfer1()],
1059
        );
1060
        $guestQuoteUuid = $quoteTransfer->getUuid();
1061
        $I->haveHttpHeader(
1062
            CartsRestApiConfig::HEADER_ANONYMOUS_CUSTOMER_UNIQUE_ID,
1063
            $guestCustomerReference,
1064
        );
1065
1066
        // Act
1067
        $I->sendPATCH(
1068
            $I->formatUrl(
1069
                '{resourceGuestCarts}/{guestCartUuid}/{resourceGuestCartItems}/',
1070
                [
1071
                    'resourceGuestCarts' => CartsRestApiConfig::RESOURCE_GUEST_CARTS,
1072
                    'guestCartUuid' => $guestQuoteUuid,
1073
                    'resourceGuestCartItems' => CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
1074
                ],
1075
            ),
1076
            [
1077
                'data' => [
1078
                    'type' => CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
1079
                    'attributes' => [
1080
                        'quantity' => $this->fixtures::QUANTITY_FOR_ITEM_UPDATE,
1081
                    ],
1082
                ],
1083
            ],
1084
        );
1085
1086
        // Assert
1087
        $I->seeResponseCodeIs(HttpCode::BAD_REQUEST);
1088
        $I->seeResponseIsJson();
1089
    }
1090
1091
    /**
1092
     * @depends loadFixtures
1093
     *
1094
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
1095
     *
1096
     * @return void
1097
     */
1098
    public function requestDeleteItemsFromGuestCart(CartsApiTester $I): void
1099
    {
1100
        // Arrange
1101
        $guestCustomerReference = $I->createGuestCustomerReference();
1102
        $quoteTransfer = $I->createPersistentQuote(
1103
            $I,
1104
            (new CustomerTransfer())->setCustomerReference(GuestCartsRestApiFixtures::ANONYMOUS_PREFIX . $guestCustomerReference),
1105
            [$this->fixtures->getProductConcreteTransfer1()],
1106
        );
1107
        $guestQuoteUuid = $quoteTransfer->getUuid();
1108
        $I->haveHttpHeader(
1109
            CartsRestApiConfig::HEADER_ANONYMOUS_CUSTOMER_UNIQUE_ID,
1110
            $guestCustomerReference,
1111
        );
1112
1113
        // Act
1114
        $I->sendDelete(
1115
            $I->formatUrl(
1116
                '{resourceGuestCarts}/{guestCartUuid}/{resourceGuestCartItems}/{itemSku}',
1117
                [
1118
                    'resourceGuestCarts' => CartsRestApiConfig::RESOURCE_GUEST_CARTS,
1119
                    'guestCartUuid' => $guestQuoteUuid,
1120
                    'resourceGuestCartItems' => CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
1121
                    'itemSku' => $this->fixtures->getProductConcreteTransfer1()->getSku(),
1122
                ],
1123
            ),
1124
        );
1125
1126
        // Assert
1127
        $I->seeResponseCodeIs(HttpCode::NO_CONTENT);
1128
    }
1129
1130
    /**
1131
     * @depends loadFixtures
1132
     *
1133
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
1134
     *
1135
     * @return void
1136
     */
1137
    public function requestDeleteItemsFromGuestCartWithoutGuestCartUuid(CartsApiTester $I): void
1138
    {
1139
        // Arrange
1140
        $I->haveHttpHeader(
1141
            CartsRestApiConfig::HEADER_ANONYMOUS_CUSTOMER_UNIQUE_ID,
1142
            $I->createGuestCustomerReference(),
1143
        );
1144
1145
        // Act
1146
        $I->sendDelete(
1147
            $I->formatUrl(
1148
                '{resourceGuestCarts}//{resourceGuestCartItems}/{itemSku}',
1149
                [
1150
                    'resourceGuestCarts' => CartsRestApiConfig::RESOURCE_GUEST_CARTS,
1151
                    'resourceGuestCartItems' => CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
1152
                    'itemSku' => $this->fixtures->getProductConcreteTransfer1()->getSku(),
1153
                ],
1154
            ),
1155
        );
1156
1157
        // Assert
1158
        $I->seeResponseCodeIs(HttpCode::BAD_REQUEST);
1159
        $I->seeResponseIsJson();
1160
    }
1161
1162
    /**
1163
     * @depends loadFixtures
1164
     *
1165
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
1166
     *
1167
     * @return void
1168
     */
1169
    public function requestDeleteItemsFromGuestCartWithoutAnonymousCustomerUniqueId(CartsApiTester $I): void
1170
    {
1171
        // Arrange
1172
        $quoteTransfer = $I->createPersistentQuote(
1173
            $I,
1174
            (new CustomerTransfer())->setCustomerReference(GuestCartsRestApiFixtures::ANONYMOUS_PREFIX . $I->createGuestCustomerReference()),
1175
            [$this->fixtures->getProductConcreteTransfer1()],
1176
        );
1177
        $guestQuoteUuid = $quoteTransfer->getUuid();
1178
1179
        // Act
1180
        $I->sendDelete(
1181
            $I->formatUrl(
1182
                '{resourceGuestCarts}/{guestCartUuid}/{resourceGuestCartItems}/{itemSku}',
1183
                [
1184
                    'resourceGuestCarts' => CartsRestApiConfig::RESOURCE_GUEST_CARTS,
1185
                    'guestCartUuid' => $guestQuoteUuid,
1186
                    'resourceGuestCartItems' => CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
1187
                    'itemSku' => $this->fixtures->getProductConcreteTransfer1()->getSku(),
1188
                ],
1189
            ),
1190
        );
1191
1192
        // Assert
1193
        $I->seeResponseCodeIs(HttpCode::BAD_REQUEST);
1194
        $I->seeResponseIsJson();
1195
    }
1196
1197
    /**
1198
     * @depends loadFixtures
1199
     *
1200
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
1201
     *
1202
     * @return void
1203
     */
1204
    public function requestDeleteItemsFromGuestCartWithoutItemSku(CartsApiTester $I): void
1205
    {
1206
        // Arrange
1207
        $guestCustomerReference = $I->createGuestCustomerReference();
1208
        $quoteTransfer = $I->createPersistentQuote(
1209
            $I,
1210
            (new CustomerTransfer())->setCustomerReference(GuestCartsRestApiFixtures::ANONYMOUS_PREFIX . $guestCustomerReference),
1211
            [$this->fixtures->getProductConcreteTransfer1()],
1212
        );
1213
        $guestQuoteUuid = $quoteTransfer->getUuid();
1214
        $I->haveHttpHeader(
1215
            CartsRestApiConfig::HEADER_ANONYMOUS_CUSTOMER_UNIQUE_ID,
1216
            $guestCustomerReference,
1217
        );
1218
1219
        // Act
1220
        $I->sendDelete(
1221
            $I->formatUrl(
1222
                '{resourceGuestCarts}/{guestCartUuid}/{resourceGuestCartItems}/',
1223
                [
1224
                    'resourceGuestCarts' => CartsRestApiConfig::RESOURCE_GUEST_CARTS,
1225
                    'guestCartUuid' => $guestQuoteUuid,
1226
                    'resourceGuestCartItems' => CartsRestApiConfig::RESOURCE_GUEST_CARTS_ITEMS,
1227
                ],
1228
            ),
1229
        );
1230
1231
        // Assert
1232
        $I->seeResponseCodeIs(HttpCode::BAD_REQUEST);
1233
        $I->seeResponseIsJson();
1234
    }
1235
}
1236