Passed
Pull Request — master (#809)
by Denys
06:35
created

requestGetSingleInquiryWithValidIdAndOrder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
eloc 18
c 1
b 1
f 1
dl 0
loc 28
rs 9.6666
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 requestCreateInquiryWithValidData(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
                    'sspAssetReference' => $this->fixtures->getAssetTransfer()->getReference(),
189
                    'orderReference' => $this->fixtures->getSaveOrderTransfer()->getOrderReference(),
190
                ],
191
            ],
192
        ];
193
194
        // Act
195
        $I->sendPost($I->getSspInquiriesUrl(), $requestPayload);
196
197
        // Assert
198
        $I->seeResponseCodeIs(HttpCode::CREATED);
199
        $I->seeResponseIsJson();
200
        $I->seeResponseMatchesOpenApiSchema();
201
202
        $I->amSure('The returned resource is of correct type')
203
            ->whenI()
204
            ->seeResponseDataContainsSingleResourceOfType(static::RESOURCE_SSP_INQUIRIES);
205
206
        $I->assertEquals('New Test Inquiry from Glue', $I->getDataFromResponseByJsonPath('$.data.attributes.subject'));
207
        $I->assertEquals('This is a test inquiry description', $I->getDataFromResponseByJsonPath('$.data.attributes.description'));
208
        $I->assertEquals('general', $I->getDataFromResponseByJsonPath('$.data.attributes.type'));
209
        $I->assertEquals($this->fixtures->getAssetTransfer()->getReference(), $I->getDataFromResponseByJsonPath('$.data.attributes.sspAssetReference'));
210
        $I->assertEquals($this->fixtures->getSaveOrderTransfer()->getOrderReference(), $I->getDataFromResponseByJsonPath('$.data.attributes.orderReference'));
211
    }
212
213
    public function requestCreateInquiryWithMissingRequiredFields(SelfServicePortalApiTester $I): void
214
    {
215
        // Arrange
216
        $I->authorizeCustomerToGlue($this->fixtures->getCustomerTransfer());
217
218
        $requestPayload = [
219
            'data' => [
220
                'type' => static::RESOURCE_SSP_INQUIRIES,
221
                'attributes' => [
222
                    // Missing required fields: subject
223
                    'description' => 'This is a test inquiry description',
224
                    'subject' => 'subject',
225
                ],
226
            ],
227
        ];
228
229
        // Act
230
        $I->sendPost($I->getSspInquiriesUrl(), $requestPayload);
231
232
        // Assert
233
        $I->seeResponseCodeIs(HttpCode::UNPROCESSABLE_ENTITY);
234
        $I->seeResponseMatchesOpenApiSchema();
235
236
        $errors = $I->getDataFromResponseByJsonPath('$.errors[0]');
237
        $I->assertEquals(HttpCode::UNPROCESSABLE_ENTITY, $errors[RestErrorMessageTransfer::STATUS]);
238
        $I->assertEquals('Inquiry type is missing.', $errors[RestErrorMessageTransfer::DETAIL]);
239
    }
240
}
241