Completed
Push — master ( 09a563...bb361a )
by Stanislav
47s queued 13s
created

requestCreateOrderInquiryWithValidData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 34
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 21
c 0
b 0
f 0
dl 0
loc 34
rs 9.584
cc 1
nc 1
nop 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\SelfServicePortal\RestApi;
11
12
use Codeception\Util\HttpCode;
13
use Generated\Shared\Transfer\RestErrorMessageTransfer;
14
use PyzTest\Glue\SelfServicePortal\RestApi\Fixtures\SspInquiriesRestApiFixtures;
15
use PyzTest\Glue\SelfServicePortal\SelfServicePortalApiTester;
16
17
/**
18
 * Auto-generated group annotations
19
 *
20
 * @group PyzTest
21
 * @group Glue
22
 * @group SelfServicePortal
23
 * @group RestApi
24
 * @group SspInquiriesRestApiCest
25
 * Add your own group annotations below this line
26
 * @group EndToEnd
27
 */
28
class SspInquiriesRestApiCest
29
{
30
    protected const RESOURCE_SSP_INQUIRIES = 'ssp-inquiries';
31
32
    protected const RESPONSE_DETAIL_INQUIRY_NOT_FOUND = 'Inquiry not found';
33
34
    protected SspInquiriesRestApiFixtures $fixtures;
35
36
    public function loadFixtures(SelfServicePortalApiTester $I): void
37
    {
38
        /** @var \PyzTest\Glue\SelfServicePortal\RestApi\Fixtures\SspInquiriesRestApiFixtures $fixtures */
39
        $fixtures = $I->loadFixtures(SspInquiriesRestApiFixtures::class);
40
        $this->fixtures = $fixtures;
41
    }
42
43
    public function requestGetInquiriesCollectionWithAuthorization(SelfServicePortalApiTester $I): void
44
    {
45
        // Arrange
46
        $I->authorizeCustomerToGlue($this->fixtures->getCustomerTransfer());
47
48
        // Act
49
        $I->sendGet($I->getSspInquiriesUrl());
50
51
        // Assert
52
        $I->seeResponseCodeIs(HttpCode::OK);
53
        $I->seeResponseIsJson();
54
        $I->seeResponseMatchesOpenApiSchema();
55
56
        $I->amSure('The returned resource is of correct type')
57
            ->whenI()
58
            ->seeResponseDataContainsResourceCollectionOfType(static::RESOURCE_SSP_INQUIRIES);
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

58
            ->/** @scrutinizer ignore-call */ seeResponseDataContainsResourceCollectionOfType(static::RESOURCE_SSP_INQUIRIES);
Loading history...
59
60
        $I->seeResponseJsonMatchesJsonPath('$.data[*].attributes.subject');
61
        $I->seeResponseJsonMatchesJsonPath('$.data[*].attributes.reference');
62
        $I->seeResponseJsonMatchesJsonPath('$.data[*].attributes.status');
63
        $I->seeResponseJsonMatchesJsonPath('$.data[*].attributes.type');
64
        $I->seeResponseJsonMatchesJsonPath('$.data[*].attributes.sspAssetReference');
65
        $I->seeResponseJsonMatchesJsonPath('$.data[*].attributes.orderReference');
66
    }
67
68
    public function requestGetSingleInquiryWithValidId(SelfServicePortalApiTester $I): void
69
    {
70
        // Arrange
71
        $I->authorizeCustomerToGlue($this->fixtures->getCustomerTransfer());
72
        $inquiryId = $this->fixtures->getInquiryTransfer()->getReferenceOrFail();
73
74
        // Act
75
        $I->sendGet($I->getSspInquiryUrl((string)$inquiryId));
76
77
        // Assert
78
        $I->seeResponseCodeIs(HttpCode::OK);
79
        $I->seeResponseIsJson();
80
        $I->seeResponseMatchesOpenApiSchema();
81
82
        $I->amSure('The returned resource is of correct type')
83
            ->whenI()
84
            ->seeResponseDataContainsSingleResourceOfType(static::RESOURCE_SSP_INQUIRIES);
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

84
            ->/** @scrutinizer ignore-call */ seeResponseDataContainsSingleResourceOfType(static::RESOURCE_SSP_INQUIRIES);
Loading history...
85
86
        $I->assertEquals($inquiryId, $I->getDataFromResponseByJsonPath('$.data.id'));
87
        $I->seeResponseJsonMatchesJsonPath('$.data.attributes.subject');
88
        $I->seeResponseJsonMatchesJsonPath('$.data.attributes.reference');
89
        $I->seeResponseJsonMatchesJsonPath('$.data.attributes.status');
90
        $I->seeResponseJsonMatchesJsonPath('$.data.attributes.type');
91
        $I->seeResponseJsonMatchesJsonPath('$.data.attributes.sspAssetReference');
92
        $I->seeResponseJsonMatchesJsonPath('$.data.attributes.orderReference');
93
94
        $I->assertResponseMatchInquiryReference($this->fixtures->getInquiryTransfer()->getReferenceOrFail());
95
    }
96
97
    public function requestGetSingleInquiryWithValidIdAndOrder(SelfServicePortalApiTester $I): void
98
    {
99
        // Arrange
100
        $I->authorizeCustomerToGlue($this->fixtures->getCustomerTransfer());
101
        $inquiryReference = $this->fixtures->getInquiryWithOrderTransfer()->getReferenceOrFail();
102
103
        // Act
104
        $I->sendGet($I->getSspInquiryUrl((string)$inquiryReference));
105
106
        // Assert
107
        $I->seeResponseCodeIs(HttpCode::OK);
108
        $I->seeResponseIsJson();
109
        $I->seeResponseMatchesOpenApiSchema();
110
111
        $I->amSure('The returned resource is of correct type')
112
            ->whenI()
113
            ->seeResponseDataContainsSingleResourceOfType(static::RESOURCE_SSP_INQUIRIES);
114
115
        $I->assertEquals($inquiryReference, $I->getDataFromResponseByJsonPath('$.data.id'));
116
        $I->seeResponseJsonMatchesJsonPath('$.data.attributes.subject');
117
        $I->seeResponseJsonMatchesJsonPath('$.data.attributes.reference');
118
        $I->seeResponseJsonMatchesJsonPath('$.data.attributes.status');
119
        $I->seeResponseJsonMatchesJsonPath('$.data.attributes.type');
120
        $I->seeResponseJsonMatchesJsonPath('$.data.attributes.sspAssetReference');
121
        $I->seeResponseJsonMatchesJsonPath('$.data.attributes.orderReference');
122
123
        $I->assertResponseMatchInquiryReference($inquiryReference);
124
        $I->assertResponseMatchOrderReferenceAttachedToInquiry($this->fixtures->getInquiryWithOrderTransfer()->getOrder()->getOrderReference());
125
    }
126
127
    public function requestGetSingleInquiryWithValidIdAndAsset(SelfServicePortalApiTester $I): void
128
    {
129
        // Arrange
130
        $I->authorizeCustomerToGlue($this->fixtures->getCustomerTransfer());
131
        $inquiryReference = $this->fixtures->getInquiryWithAssetTransfer()->getReferenceOrFail();
132
133
        // Act
134
        $I->sendGet($I->getSspInquiryUrl((string)$inquiryReference));
135
136
        // Assert
137
        $I->seeResponseCodeIs(HttpCode::OK);
138
        $I->seeResponseIsJson();
139
        $I->seeResponseMatchesOpenApiSchema();
140
141
        $I->amSure('The returned resource is of correct type')
142
            ->whenI()
143
            ->seeResponseDataContainsSingleResourceOfType(static::RESOURCE_SSP_INQUIRIES);
144
145
        $I->assertEquals($inquiryReference, $I->getDataFromResponseByJsonPath('$.data.id'));
146
        $I->seeResponseJsonMatchesJsonPath('$.data.attributes.subject');
147
        $I->seeResponseJsonMatchesJsonPath('$.data.attributes.reference');
148
        $I->seeResponseJsonMatchesJsonPath('$.data.attributes.status');
149
        $I->seeResponseJsonMatchesJsonPath('$.data.attributes.type');
150
        $I->seeResponseJsonMatchesJsonPath('$.data.attributes.sspAssetReference');
151
        $I->seeResponseJsonMatchesJsonPath('$.data.attributes.orderReference');
152
153
        $I->assertResponseMatchInquiryReference($inquiryReference);
154
        $I->assertResponseMatchAssetReferenceAttachedToInquiry($this->fixtures->getInquiryWithAssetTransfer()->getSspAsset()->getReference());
155
    }
156
157
    public function requestGetSingleInquiryWithInvalidId(SelfServicePortalApiTester $I): void
158
    {
159
        // Arrange
160
        $I->authorizeCustomerToGlue($this->fixtures->getCustomerTransfer());
161
        $invalidInquiryId = '999999';
162
163
        // Act
164
        $I->sendGet($I->getSspInquiryUrl($invalidInquiryId));
165
166
        // Assert
167
        $I->seeResponseCodeIs(HttpCode::NOT_FOUND);
168
        $I->seeResponseIsJson();
169
        $I->seeResponseMatchesOpenApiSchema();
170
171
        $errors = $I->getDataFromResponseByJsonPath('$.errors[0]');
172
        $I->assertEquals($errors[RestErrorMessageTransfer::STATUS], HttpCode::NOT_FOUND);
173
        $I->assertEquals($errors[RestErrorMessageTransfer::DETAIL], static::RESPONSE_DETAIL_INQUIRY_NOT_FOUND);
174
    }
175
176
    public function requestCreateGeneralInquiryWithValidData(SelfServicePortalApiTester $I): void
177
    {
178
        // Arrange
179
        $I->authorizeCustomerToGlue($this->fixtures->getCustomerTransfer());
180
181
        $requestPayload = [
182
            'data' => [
183
                'type' => static::RESOURCE_SSP_INQUIRIES,
184
                'attributes' => [
185
                    'subject' => 'New Test Inquiry from Glue',
186
                    'description' => 'This is a test inquiry description',
187
                    'type' => 'general',
188
                ],
189
            ],
190
        ];
191
192
        // Act
193
        $I->sendPost($I->getSspInquiriesUrl(), $requestPayload);
194
195
        // Assert
196
        $I->seeResponseCodeIs(HttpCode::CREATED);
197
        $I->seeResponseIsJson();
198
        $I->seeResponseMatchesOpenApiSchema();
199
200
        $I->amSure('The returned resource is of correct type')
201
            ->whenI()
202
            ->seeResponseDataContainsSingleResourceOfType(static::RESOURCE_SSP_INQUIRIES);
203
204
        $I->assertEquals('New Test Inquiry from Glue', $I->getDataFromResponseByJsonPath('$.data.attributes.subject'));
205
        $I->assertEquals('This is a test inquiry description', $I->getDataFromResponseByJsonPath('$.data.attributes.description'));
206
        $I->assertEquals('general', $I->getDataFromResponseByJsonPath('$.data.attributes.type'));
207
        $I->assertEquals(null, $I->getDataFromResponseByJsonPath('$.data.attributes.sspAssetReference'));
208
        $I->assertEquals(null, $I->getDataFromResponseByJsonPath('$.data.attributes.orderReference'));
209
    }
210
211
    public function requestCreateInquiryWithMissingRequiredFields(SelfServicePortalApiTester $I): void
212
    {
213
        // Arrange
214
        $I->authorizeCustomerToGlue($this->fixtures->getCustomerTransfer());
215
216
        $requestPayload = [
217
            'data' => [
218
                'type' => static::RESOURCE_SSP_INQUIRIES,
219
                'attributes' => [
220
                    'description' => 'This is a test inquiry description',
221
                    'subject' => 'subject',
222
                ],
223
            ],
224
        ];
225
226
        // Act
227
        $I->sendPost($I->getSspInquiriesUrl(), $requestPayload);
228
229
        // Assert
230
        $I->seeResponseCodeIs(HttpCode::BAD_REQUEST);
231
        $I->seeResponseMatchesOpenApiSchema();
232
233
        $errors = $I->getDataFromResponseByJsonPath('$.errors[0]');
234
        $I->assertEquals(HttpCode::BAD_REQUEST, $errors[RestErrorMessageTransfer::STATUS]);
235
        $I->assertEquals('Type is required.', $errors[RestErrorMessageTransfer::DETAIL]);
236
    }
237
238
    public function requestCreateOrderInquiryWithValidData(SelfServicePortalApiTester $I): void
239
    {
240
        // Arrange
241
        $I->authorizeCustomerToGlue($this->fixtures->getCustomerTransfer());
242
243
        $requestPayload = [
244
            'data' => [
245
                'type' => static::RESOURCE_SSP_INQUIRIES,
246
                'attributes' => [
247
                    'subject' => 'New Test Inquiry from Glue',
248
                    'description' => 'This is a test inquiry description',
249
                    'type' => 'order',
250
                    'orderReference' => $this->fixtures->getSaveOrderTransfer()->getOrderReference(),
251
                ],
252
            ],
253
        ];
254
255
        // Act
256
        $I->sendPost($I->getSspInquiriesUrl(), $requestPayload);
257
258
        // Assert
259
        $I->seeResponseCodeIs(HttpCode::CREATED);
260
        $I->seeResponseIsJson();
261
        $I->seeResponseMatchesOpenApiSchema();
262
263
        $I->amSure('The returned resource is of correct type')
264
            ->whenI()
265
            ->seeResponseDataContainsSingleResourceOfType(static::RESOURCE_SSP_INQUIRIES);
266
267
        $I->assertEquals('New Test Inquiry from Glue', $I->getDataFromResponseByJsonPath('$.data.attributes.subject'));
268
        $I->assertEquals('This is a test inquiry description', $I->getDataFromResponseByJsonPath('$.data.attributes.description'));
269
        $I->assertEquals('order', $I->getDataFromResponseByJsonPath('$.data.attributes.type'));
270
        $I->assertEquals(null, $I->getDataFromResponseByJsonPath('$.data.attributes.sspAssetReference'));
271
        $I->assertEquals($this->fixtures->getSaveOrderTransfer()->getOrderReference(), $I->getDataFromResponseByJsonPath('$.data.attributes.orderReference'));
272
    }
273
274
    public function requestCreateOrderInquiryWithoutOrderReference(SelfServicePortalApiTester $I): void
275
    {
276
        // Arrange
277
        $I->authorizeCustomerToGlue($this->fixtures->getCustomerTransfer());
278
279
        $requestPayload = [
280
            'data' => [
281
                'type' => static::RESOURCE_SSP_INQUIRIES,
282
                'attributes' => [
283
                    'subject' => 'New Test Inquiry from Glue',
284
                    'description' => 'This is a test inquiry description',
285
                    'type' => 'order',
286
                ],
287
            ],
288
        ];
289
290
        // Act
291
        $I->sendPost($I->getSspInquiriesUrl(), $requestPayload);
292
293
        // Assert
294
        $I->seeResponseCodeIs(HttpCode::BAD_REQUEST);
295
        $I->seeResponseMatchesOpenApiSchema();
296
297
        $errors = $I->getDataFromResponseByJsonPath('$.errors[0]');
298
        $I->assertEquals(HttpCode::BAD_REQUEST, $errors[RestErrorMessageTransfer::STATUS]);
299
        $I->assertEquals('Order reference is required.', $errors[RestErrorMessageTransfer::DETAIL]);
300
    }
301
}
302