Passed
Pull Request — master (#356)
by Denys
05:13
created

requestAddConfigurableItemsToCart()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 63
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 40
dl 0
loc 63
rs 9.28
c 1
b 0
f 0
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\ProductConfigurations\RestApi;
9
10
use Codeception\Util\HttpCode;
11
use Generated\Shared\Transfer\QuoteTransfer;
12
use Generated\Shared\Transfer\StoreTransfer;
13
use PyzTest\Glue\ProductConfigurations\ProductConfigurationsApiTester;
14
use PyzTest\Glue\ProductConfigurations\RestApi\Fixtures\ProductConfigurationsRestApiFixtures;
15
use Spryker\Glue\CartsRestApi\CartsRestApiConfig;
16
use Spryker\Glue\OrdersRestApi\OrdersRestApiConfig;
17
use Spryker\Glue\ProductsRestApi\ProductsRestApiConfig;
18
use Spryker\Shared\Price\PriceConfig;
19
20
/**
21
 * Auto-generated group annotations
22
 *
23
 * @group PyzTest
24
 * @group Glue
25
 * @group ProductConfigurations
26
 * @group RestApi
27
 * @group ProductConfigurationRestApiCest
28
 * Add your own group annotations below this line
29
 * @group EndToEnd
30
 */
31
class ProductConfigurationRestApiCest
32
{
33
    /**
34
     * @var \PyzTest\Glue\ProductConfigurations\RestApi\Fixtures\ProductConfigurationsRestApiFixtures
35
     */
36
    protected ProductConfigurationsRestApiFixtures $fixtures;
37
38
    /**
39
     * @param \PyzTest\Glue\ProductConfigurations\ProductConfigurationsApiTester $I
40
     *
41
     * @return void
42
     */
43
    public function loadFixtures(ProductConfigurationsApiTester $I): void
44
    {
45
        /** @var \PyzTest\Glue\ProductConfigurations\RestApi\Fixtures\ProductConfigurationsRestApiFixtures $fixtures */
46
        $fixtures = $I->loadFixtures(ProductConfigurationsRestApiFixtures::class);
47
48
        $this->fixtures = $fixtures;
49
    }
50
51
    /**
52
     * @depends loadFixtures
53
     *
54
     * @param \PyzTest\Glue\ProductConfigurations\ProductConfigurationsApiTester $I
55
     *
56
     * @return void
57
     */
58
    public function requestProductConcrete(ProductConfigurationsApiTester $I): void
59
    {
60
        $url = $I->formatFullUrl(
0 ignored issues
show
Unused Code introduced by
The assignment to $url is dead and can be removed.
Loading history...
61
            '{resourceConcreteProducts}/{productConcreteSku}',
62
            [
63
                'resourceConcreteProducts' => ProductsRestApiConfig::RESOURCE_CONCRETE_PRODUCTS,
64
                'productConcreteSku' => $this->fixtures->getProductConcreteTransfer()->getSkuOrFail(),
65
            ],
66
        );
67
        // Act
68
        $I->sendGET($I->formatFullUrl(
69
            '{resourceConcreteProducts}/{productConcreteSku}',
70
            [
71
                'resourceConcreteProducts' => ProductsRestApiConfig::RESOURCE_CONCRETE_PRODUCTS,
72
                'productConcreteSku' => $this->fixtures->getProductConcreteTransfer()->getSkuOrFail(),
73
            ],
74
        ));
75
76
        // Assert
77
        $I->seeResponseCodeIs(HttpCode::OK);
78
        $I->seeResponseIsJson();
79
        $I->seeResponseMatchesOpenApiSchema();
80
81
        $I->amSure('Returned resource is of type concrete-products')
82
            ->whenI()
83
            ->seeResponseDataContainsSingleResourceOfType(ProductsRestApiConfig::RESOURCE_CONCRETE_PRODUCTS);
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

83
            ->/** @scrutinizer ignore-call */ seeResponseDataContainsSingleResourceOfType(ProductsRestApiConfig::RESOURCE_CONCRETE_PRODUCTS);
Loading history...
84
85
        $I->amSure('Returned resource has correct id')
86
            ->whenI()
87
            ->seeSingleResourceIdEqualTo($this->fixtures->getProductConcreteTransfer()->getSkuOrFail());
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

87
            ->/** @scrutinizer ignore-call */ seeSingleResourceIdEqualTo($this->fixtures->getProductConcreteTransfer()->getSkuOrFail());
Loading history...
88
89
        $I->amSure('Returned resource has product configuration instance')
90
            ->whenI()
91
            ->seeSingleResourceHasAttribute($this->fixtures::PRODUCT_CONFIGURATION_INSTANCE_ATTRIBUTE_JSON_PATH);
0 ignored issues
show
Bug introduced by
It seems like seeSingleResourceHasAttribute() 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

91
            ->/** @scrutinizer ignore-call */ seeSingleResourceHasAttribute($this->fixtures::PRODUCT_CONFIGURATION_INSTANCE_ATTRIBUTE_JSON_PATH);
Loading history...
92
93
        $I->amSure('Returned product configuration instance is correct')
94
            ->whenI()
95
            ->seeProductConfigurationInstanceEqualToExpectedValue($this->fixtures->getProductConfigurationTransfer());
0 ignored issues
show
Bug introduced by
It seems like seeProductConfigurationI...eEqualToExpectedValue() 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

95
            ->/** @scrutinizer ignore-call */ seeProductConfigurationInstanceEqualToExpectedValue($this->fixtures->getProductConfigurationTransfer());
Loading history...
96
    }
97
98
    /**
99
     * @param \PyzTest\Glue\ProductConfigurations\ProductConfigurationsApiTester $I
100
     *
101
     * @return void
102
     */
103
    public function requestAddConfigurableItemsToCart(ProductConfigurationsApiTester $I): void
104
    {
105
        // Arrange
106
        $I->amAuthorizedCustomer($this->fixtures->getCustomerTransfer());
107
        $quoteTransfer = $I->havePersistentQuote([
108
            QuoteTransfer::CUSTOMER => $this->fixtures->getCustomerTransfer(),
109
            QuoteTransfer::STORE => [StoreTransfer::NAME => $this->fixtures::STORE_NAME_DE],
110
            QuoteTransfer::PRICE_MODE => PriceConfig::PRICE_MODE_GROSS,
111
        ]);
112
        $quoteUuid = $quoteTransfer->getUuidOrFail();
113
        $productConcreteSku = $this->fixtures->getProductConcreteTransfer()->getSkuOrFail();
114
115
        // Act
116
        $I->sendPOST(
117
            $I->formatUrl(
118
                '{resourceCarts}/{cartUuid}/{resourceCartItems}?include={resourceCartItems}',
119
                [
120
                    'resourceCarts' => CartsRestApiConfig::RESOURCE_CARTS,
121
                    'cartUuid' => $quoteUuid,
122
                    'resourceCartItems' => CartsRestApiConfig::RESOURCE_CART_ITEMS,
123
                ],
124
            ),
125
            [
126
                'data' => [
127
                    'type' => CartsRestApiConfig::RESOURCE_CART_ITEMS,
128
                    'attributes' => [
129
                        'sku' => $productConcreteSku,
130
                        'quantity' => 1,
131
                        'productConfigurationInstance' => $this->fixtures::PRODUCT_CONFIGURATION_CART_ITEM_DATA,
132
                    ],
133
                ],
134
            ],
135
        );
136
137
        // Assert
138
        $I->seeResponseCodeIs(HttpCode::CREATED);
139
        $I->seeResponseMatchesOpenApiSchema();
140
141
        $I->amSure('Returned resource has correct id')
142
            ->whenI()
143
            ->seeSingleResourceIdEqualTo($quoteUuid);
144
145
        $I->amSure(sprintf('Returned resource is of type %s', CartsRestApiConfig::RESOURCE_CARTS))
146
            ->whenI()
147
            ->seeResponseDataContainsSingleResourceOfType(CartsRestApiConfig::RESOURCE_CARTS);
148
149
        $I->amSure('Returned resource has include of type items')
150
            ->whenI()
151
            ->seeIncludesContainResourceOfType(CartsRestApiConfig::RESOURCE_CART_ITEMS);
0 ignored issues
show
Bug introduced by
It seems like seeIncludesContainResourceOfType() 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

151
            ->/** @scrutinizer ignore-call */ seeIncludesContainResourceOfType(CartsRestApiConfig::RESOURCE_CART_ITEMS);
Loading history...
152
153
        $I->amSure('Included resource has product configuration instance')
154
            ->whenI()
155
            ->seeCartItemContainsProductConfigurationInstance(
0 ignored issues
show
Bug introduced by
It seems like seeCartItemContainsProductConfigurationInstance() 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

155
            ->/** @scrutinizer ignore-call */ seeCartItemContainsProductConfigurationInstance(
Loading history...
156
                CartsRestApiConfig::RESOURCE_CART_ITEMS,
157
                $productConcreteSku,
158
            );
159
160
        $I->seeSingleResourceHasSelfLink(
161
            $I->formatFullUrl(
162
                '{resourceCarts}/{cartUuid}',
163
                [
164
                    'resourceCarts' => CartsRestApiConfig::RESOURCE_CARTS,
165
                    'cartUuid' => $I->getDataFromResponseByJsonPath('$.data')['id'],
166
                ],
167
            ),
168
        );
169
    }
170
171
    /**
172
     * @param \PyzTest\Glue\ProductConfigurations\ProductConfigurationsApiTester $I
173
     *
174
     * @return void
175
     */
176
    public function requestGetOrderDetails(ProductConfigurationsApiTester $I): void
177
    {
178
        // Arrange
179
        $I->amAuthorizedCustomer($this->fixtures->getCustomerTransfer());
180
        $orderReference = $this->fixtures->getSaveOrderTransfer()->getOrderReferenceOrFail();
181
182
        // Act
183
        $I->sendGET(
184
            $I->formatUrl(
185
                '{orders}/{customerOrderReference}?include=items',
186
                [
187
                    'orders' => OrdersRestApiConfig::RESOURCE_ORDERS,
188
                    'customerOrderReference' => $orderReference,
189
                ],
190
            ),
191
        );
192
193
        // Assert
194
        $I->seeResponseCodeIs(HttpCode::OK);
195
        $I->seeResponseIsJson();
196
        $I->seeResponseMatchesOpenApiSchema();
197
198
        $I->amSure('The returned resource is of correct type')
199
            ->whenI()
200
            ->seeResponseDataContainsSingleResourceOfType('orders');
201
202
        $I->amSure('The returned resource has correct id')
203
            ->whenI()
204
            ->seeSingleResourceIdEqualTo($orderReference);
205
206
        $I->amSure('Order item contains product configuration data')
207
            ->whenI()
208
            ->seeOrderItemContainProductConfigurationInstance($this->fixtures->getProductConfigurationTransfer());
0 ignored issues
show
Bug introduced by
It seems like seeOrderItemContainProductConfigurationInstance() 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

208
            ->/** @scrutinizer ignore-call */ seeOrderItemContainProductConfigurationInstance($this->fixtures->getProductConfigurationTransfer());
Loading history...
209
    }
210
}
211