Completed
Push — master ( f465c8...ce649b )
by Ilya
52s queued 19s
created

OrderAmendmentsRestApiCest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 147
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 4
eloc 59
c 1
b 1
f 0
dl 0
loc 147
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A loadFixtures() 0 5 1
A requestCreateOrderAmendmentWithInvalidOrder() 0 27 1
A requestCreateOrderAmendmentWithValidOrder() 0 35 1
A requestCreateOrderAmendmentWithEmptyIsAmendmentParameter() 0 27 1
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\OrderAmendments\RestApi;
11
12
use Codeception\Util\HttpCode;
13
use Generated\Shared\Transfer\RestCheckoutErrorTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...stCheckoutErrorTransfer 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...
14
use PyzTest\Glue\OrderAmendments\OrderAmendmentsApiTester;
15
use PyzTest\Glue\OrderAmendments\RestApi\Fixtures\OrderAmendmentRestApiFixtures;
16
use Spryker\Glue\CartReorderRestApi\CartReorderRestApiConfig;
17
18
/**
19
 * Auto-generated group annotations
20
 *
21
 * @group PyzTest
22
 * @group Glue
23
 * @group OrderAmendments
24
 * @group RestApi
25
 * @group OrderAmendmentsRestApiCest
26
 * Add your own group annotations below this line
27
 * @group EndToEnd
28
 */
29
class OrderAmendmentsRestApiCest
30
{
31
    /**
32
     * @var string
33
     */
34
    protected const RESPONSE_CODE_ORDER_IS_NOT_AMENDABLE = '5800';
35
36
    /**
37
     * @var string
38
     */
39
    protected const RESPONSE_DETAIL_ORDER_IS_NOT_AMENDABLE = 'The order cannot be amended.';
40
41
    /**
42
     * @var string
43
     */
44
    protected const RESPONSE_CODE_PARAMETER_IS_AMENDABLE_INVALID = '901';
45
46
    /**
47
     * @var string
48
     */
49
    protected const RESPONSE_DETAIL_PARAMETER_IS_AMENDABLE_INVALID = 'isAmendment => This value should be of type bool.';
50
51
    /**
52
     * @var \PyzTest\Glue\OrderAmendments\RestApi\Fixtures\OrderAmendmentRestApiFixtures
53
     */
54
    protected OrderAmendmentRestApiFixtures $fixtures;
55
56
    /**
57
     * @param \PyzTest\Glue\OrderAmendments\OrderAmendmentsApiTester $I
58
     *
59
     * @return void
60
     */
61
    public function loadFixtures(OrderAmendmentsApiTester $I): void
62
    {
63
        /** @var \PyzTest\Glue\OrderAmendments\RestApi\Fixtures\OrderAmendmentRestApiFixtures $fixtures */
64
        $fixtures = $I->loadFixtures(OrderAmendmentRestApiFixtures::class);
65
        $this->fixtures = $fixtures;
66
    }
67
68
    /**
69
     * @param \PyzTest\Glue\OrderAmendments\OrderAmendmentsApiTester $I
70
     *
71
     * @return void
72
     */
73
    public function requestCreateOrderAmendmentWithInvalidOrder(OrderAmendmentsApiTester $I): void
74
    {
75
        //Arrange
76
        $I->authorizeCustomerToGlue($this->fixtures->getCustomerTransfer());
77
78
        $requestPayload = [
79
            'data' => [
80
                'type' => CartReorderRestApiConfig::RESOURCE_CART_REORDER,
81
                'attributes' => [
82
                    'orderReference' => $this->fixtures->getNotReadyForAmendmentOrderTransfer()->getOrderReferenceOrFail(),
83
                    'isAmendment' => true,
84
                ],
85
            ],
86
        ];
87
88
        // Act
89
        $I->sendPost($I->getCartReorderUrl(), $requestPayload);
90
91
        // Assert
92
        $I->seeResponseCodeIs(HttpCode::UNPROCESSABLE_ENTITY);
93
        $I->seeResponseIsJson();
94
        $I->seeResponseMatchesOpenApiSchema();
95
96
        $errors = $I->getDataFromResponseByJsonPath('$.errors[0]');
97
        $I->assertEquals($errors[RestCheckoutErrorTransfer::CODE], static::RESPONSE_CODE_ORDER_IS_NOT_AMENDABLE);
98
        $I->assertEquals($errors[RestCheckoutErrorTransfer::STATUS], HttpCode::UNPROCESSABLE_ENTITY);
99
        $I->assertEquals($errors[RestCheckoutErrorTransfer::DETAIL], static::RESPONSE_DETAIL_ORDER_IS_NOT_AMENDABLE);
100
    }
101
102
    /**
103
     * @param \PyzTest\Glue\OrderAmendments\OrderAmendmentsApiTester $I
104
     *
105
     * @return void
106
     */
107
    public function requestCreateOrderAmendmentWithEmptyIsAmendmentParameter(OrderAmendmentsApiTester $I): void
108
    {
109
        //Arrange
110
        $I->authorizeCustomerToGlue($this->fixtures->getCustomerTransfer());
111
112
        $requestPayload = [
113
            'data' => [
114
                'type' => CartReorderRestApiConfig::RESOURCE_CART_REORDER,
115
                'attributes' => [
116
                    'orderReference' => $this->fixtures->getReadyForAmendmentOrderTransfer()->getOrderReferenceOrFail(),
117
                    'isAmendment' => '',
118
                ],
119
            ],
120
        ];
121
122
        // Act
123
        $I->sendPost($I->getCartReorderUrl(), $requestPayload);
124
125
        // Assert
126
        $I->seeResponseCodeIs(HttpCode::UNPROCESSABLE_ENTITY);
127
        $I->seeResponseIsJson();
128
        $I->seeResponseMatchesOpenApiSchema();
129
130
        $errors = $I->getDataFromResponseByJsonPath('$.errors[0]');
131
        $I->assertEquals($errors[RestCheckoutErrorTransfer::CODE], static::RESPONSE_CODE_PARAMETER_IS_AMENDABLE_INVALID);
132
        $I->assertEquals($errors[RestCheckoutErrorTransfer::STATUS], HttpCode::UNPROCESSABLE_ENTITY);
133
        $I->assertEquals($errors[RestCheckoutErrorTransfer::DETAIL], static::RESPONSE_DETAIL_PARAMETER_IS_AMENDABLE_INVALID);
134
    }
135
136
    /**
137
     * @param \PyzTest\Glue\OrderAmendments\OrderAmendmentsApiTester $I
138
     *
139
     * @return void
140
     */
141
    public function requestCreateOrderAmendmentWithValidOrder(OrderAmendmentsApiTester $I): void
142
    {
143
        //Arrange
144
        $I->authorizeCustomerToGlue($this->fixtures->getCustomerTransfer());
145
146
        $requestPayload = [
147
            'data' => [
148
                'type' => CartReorderRestApiConfig::RESOURCE_CART_REORDER,
149
                'attributes' => [
150
                    'orderReference' => $this->fixtures->getReadyForAmendmentOrderTransfer()->getOrderReferenceOrFail(),
151
                    'isAmendment' => true,
152
                ],
153
            ],
154
        ];
155
156
        // Act
157
        $I->sendPost($I->getCartReorderUrl(), $requestPayload);
158
159
        // Assert
160
        $I->seeResponseCodeIs(HttpCode::CREATED);
161
        $I->seeResponseIsJson();
162
        $I->seeResponseMatchesOpenApiSchema();
163
164
        $I->amSure('The returned resource is of correct type')
165
            ->whenI()
166
            ->seeResponseDataContainsSingleResourceOfType('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

166
            ->/** @scrutinizer ignore-call */ seeResponseDataContainsSingleResourceOfType('carts');
Loading history...
167
168
        $I->amSure('The returned response data contains amendment order reference')
169
            ->whenI()
170
            ->assertResponseContainsAmendmentOrderReference($this->fixtures->getReadyForAmendmentOrderTransfer()->getOrderReferenceOrFail());
0 ignored issues
show
Bug introduced by
It seems like assertResponseContainsAmendmentOrderReference() 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

170
            ->/** @scrutinizer ignore-call */ assertResponseContainsAmendmentOrderReference($this->fixtures->getReadyForAmendmentOrderTransfer()->getOrderReferenceOrFail());
Loading history...
171
172
        $I->amSure('The returned response data contains correct cart name')
173
            ->whenI()
174
            ->assertResponseContainsCorrectCartName(
0 ignored issues
show
Bug introduced by
It seems like assertResponseContainsCorrectCartName() 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

174
            ->/** @scrutinizer ignore-call */ assertResponseContainsCorrectCartName(
Loading history...
175
                sprintf('Editing Order %s', $this->fixtures->getReadyForAmendmentOrderTransfer()->getOrderReferenceOrFail()),
176
            );
177
    }
178
}
179