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\Wishlists\RestApi; |
11
|
|
|
|
12
|
|
|
use Codeception\Util\HttpCode; |
13
|
|
|
use PyzTest\Glue\Wishlists\WishlistsApiTester; |
14
|
|
|
use Spryker\Glue\ProductsRestApi\ProductsRestApiConfig; |
15
|
|
|
use Spryker\Glue\WishlistsRestApi\WishlistsRestApiConfig; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Auto-generated group annotations |
19
|
|
|
* |
20
|
|
|
* @group PyzTest |
21
|
|
|
* @group Glue |
22
|
|
|
* @group Wishlists |
23
|
|
|
* @group RestApi |
24
|
|
|
* @group WishlistRestApiCest |
25
|
|
|
* Add your own group annotations below this line |
26
|
|
|
* @group EndToEnd |
27
|
|
|
*/ |
28
|
|
|
class WishlistRestApiCest |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var \PyzTest\Glue\Wishlists\RestApi\WishlistsRestApiFixtures |
32
|
|
|
*/ |
33
|
|
|
protected WishlistsRestApiFixtures $fixtures; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param \PyzTest\Glue\Wishlists\WishlistsApiTester $I |
37
|
|
|
* |
38
|
|
|
* @return void |
39
|
|
|
*/ |
40
|
|
|
public function loadFixtures(WishlistsApiTester $I): void |
41
|
|
|
{ |
42
|
|
|
/** @var \PyzTest\Glue\Wishlists\RestApi\WishlistsRestApiFixtures $fixtures */ |
43
|
|
|
$fixtures = $I->loadFixtures(WishlistsRestApiFixtures::class); |
44
|
|
|
|
45
|
|
|
$this->fixtures = $fixtures; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @depends loadFixtures |
50
|
|
|
* |
51
|
|
|
* @param \PyzTest\Glue\Wishlists\WishlistsApiTester $I |
52
|
|
|
* |
53
|
|
|
* @return void |
54
|
|
|
*/ |
55
|
|
|
public function requestWishlistByUuid(WishlistsApiTester $I): void |
56
|
|
|
{ |
57
|
|
|
// Arrange |
58
|
|
|
$wishlistUuid = $this->fixtures->getWishlistTransfer()->getUuid(); |
59
|
|
|
$oauthResponseTransfer = $I->haveAuthorizationToGlue($this->fixtures->getCustomerTransfer()); |
60
|
|
|
$I->amBearerAuthenticated($oauthResponseTransfer->getAccessToken()); |
61
|
|
|
$url = $I->buildWishlistUrl($wishlistUuid); |
62
|
|
|
|
63
|
|
|
// Act |
64
|
|
|
$I->sendGET($url); |
65
|
|
|
|
66
|
|
|
// Assert |
67
|
|
|
$I->seeResponseCodeIs(HttpCode::OK); |
68
|
|
|
$I->seeResponseIsJson(); |
69
|
|
|
$I->seeResponseMatchesOpenApiSchema(); |
70
|
|
|
|
71
|
|
|
$I->amSure('returned resource is of correct type') |
72
|
|
|
->whenI() |
73
|
|
|
->seeResponseDataContainsSingleResourceOfType(WishlistsRestApiConfig::RESOURCE_WISHLISTS); |
|
|
|
|
74
|
|
|
|
75
|
|
|
$I->amSure('returned resource has correct id') |
76
|
|
|
->whenI() |
77
|
|
|
->seeSingleResourceIdEqualTo($wishlistUuid); |
|
|
|
|
78
|
|
|
|
79
|
|
|
$I->amSure('returned resource has correct self-link') |
80
|
|
|
->whenI() |
81
|
|
|
->seeSingleResourceHasSelfLink($url); |
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @depends loadFixtures |
86
|
|
|
* |
87
|
|
|
* @param \PyzTest\Glue\Wishlists\WishlistsApiTester $I |
88
|
|
|
* |
89
|
|
|
* @return void |
90
|
|
|
*/ |
91
|
|
|
public function requestWishlists(WishlistsApiTester $I): void |
92
|
|
|
{ |
93
|
|
|
// Arrange |
94
|
|
|
$oauthResponseTransfer = $I->haveAuthorizationToGlue($this->fixtures->getCustomerTransfer()); |
95
|
|
|
$I->amBearerAuthenticated($oauthResponseTransfer->getAccessToken()); |
96
|
|
|
$wishlistUuid = $this->fixtures->getWishlistTransfer()->getUuid(); |
97
|
|
|
|
98
|
|
|
// Act |
99
|
|
|
$I->sendGET($I->buildWishlistsUrl()); |
100
|
|
|
|
101
|
|
|
// Assert |
102
|
|
|
$I->seeResponseCodeIs(HttpCode::OK); |
103
|
|
|
$I->seeResponseIsJson(); |
104
|
|
|
$I->seeResponseMatchesOpenApiSchema(); |
105
|
|
|
|
106
|
|
|
$I->amSure('Response data contains resource collection') |
107
|
|
|
->whenI() |
108
|
|
|
->seeResponseDataContainsResourceCollectionOfType(WishlistsRestApiConfig::RESOURCE_WISHLISTS); |
|
|
|
|
109
|
|
|
|
110
|
|
|
$I->amSure('Resource collection has resource') |
111
|
|
|
->whenI() |
112
|
|
|
->seeResourceCollectionHasResourceWithId($wishlistUuid); |
|
|
|
|
113
|
|
|
|
114
|
|
|
$I->amSure('Resource has correct self-link') |
115
|
|
|
->whenI() |
116
|
|
|
->seeResourceByIdHasSelfLink($wishlistUuid, $I->buildWishlistUrl($wishlistUuid)); |
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @depends loadFixtures |
121
|
|
|
* |
122
|
|
|
* @param \PyzTest\Glue\Wishlists\WishlistsApiTester $I |
123
|
|
|
* |
124
|
|
|
* @return void |
125
|
|
|
*/ |
126
|
|
|
public function requestWishlistByUuidWithWishlistItemsRelationship(WishlistsApiTester $I): void |
127
|
|
|
{ |
128
|
|
|
// Arrange |
129
|
|
|
$wishlistUuid = $this->fixtures->getWishlistTransfer()->getUuid(); |
130
|
|
|
$productConcreteSku = $this->fixtures->getProductConcreteTransfer()->getSku(); |
131
|
|
|
$oauthResponseTransfer = $I->haveAuthorizationToGlue($this->fixtures->getCustomerTransfer()); |
132
|
|
|
$I->amBearerAuthenticated($oauthResponseTransfer->getAccessToken()); |
133
|
|
|
$url = $I->buildWishlistUrl( |
134
|
|
|
$wishlistUuid, |
135
|
|
|
[ |
136
|
|
|
WishlistsRestApiConfig::RESOURCE_WISHLIST_ITEMS, |
137
|
|
|
], |
138
|
|
|
); |
139
|
|
|
|
140
|
|
|
// Act |
141
|
|
|
$I->sendGET($url); |
142
|
|
|
|
143
|
|
|
// Assert |
144
|
|
|
$I->seeResponseCodeIs(HttpCode::OK); |
145
|
|
|
$I->seeResponseIsJson(); |
146
|
|
|
$I->seeResponseMatchesOpenApiSchema(); |
147
|
|
|
|
148
|
|
|
$I->amSure('returned resource has relationship') |
149
|
|
|
->whenI() |
150
|
|
|
->seeSingleResourceHasRelationshipByTypeAndId( |
|
|
|
|
151
|
|
|
WishlistsRestApiConfig::RESOURCE_WISHLIST_ITEMS, |
152
|
|
|
$productConcreteSku, |
153
|
|
|
); |
154
|
|
|
|
155
|
|
|
$I->amSure('returned resource has include') |
156
|
|
|
->whenI() |
157
|
|
|
->seeIncludesContainsResourceByTypeAndId( |
|
|
|
|
158
|
|
|
WishlistsRestApiConfig::RESOURCE_WISHLIST_ITEMS, |
159
|
|
|
$productConcreteSku, |
160
|
|
|
); |
161
|
|
|
|
162
|
|
|
$I->amSure('include has correct self-link') |
163
|
|
|
->whenI() |
164
|
|
|
->seeIncludedResourceByTypeAndIdHasSelfLink( |
|
|
|
|
165
|
|
|
WishlistsRestApiConfig::RESOURCE_WISHLIST_ITEMS, |
166
|
|
|
$productConcreteSku, |
167
|
|
|
$I->buildWishlistItemUrl($wishlistUuid, $productConcreteSku), |
168
|
|
|
); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @depends loadFixtures |
173
|
|
|
* |
174
|
|
|
* @param \PyzTest\Glue\Wishlists\WishlistsApiTester $I |
175
|
|
|
* |
176
|
|
|
* @return void |
177
|
|
|
*/ |
178
|
|
|
public function requestWishlistByUuidWithProductConcreteRelationship(WishlistsApiTester $I): void |
179
|
|
|
{ |
180
|
|
|
// Arrange |
181
|
|
|
$productConcreteSku = $this->fixtures->getProductConcreteTransfer()->getSku(); |
182
|
|
|
$oauthResponseTransfer = $I->haveAuthorizationToGlue($this->fixtures->getCustomerTransfer()); |
183
|
|
|
$I->amBearerAuthenticated($oauthResponseTransfer->getAccessToken()); |
184
|
|
|
$url = $I->buildWishlistUrl( |
185
|
|
|
$this->fixtures->getWishlistTransfer()->getUuid(), |
186
|
|
|
[ |
187
|
|
|
WishlistsRestApiConfig::RESOURCE_WISHLIST_ITEMS, |
188
|
|
|
ProductsRestApiConfig::RESOURCE_CONCRETE_PRODUCTS, |
189
|
|
|
], |
190
|
|
|
); |
191
|
|
|
|
192
|
|
|
// Act |
193
|
|
|
$I->sendGET($url); |
194
|
|
|
|
195
|
|
|
// Assert |
196
|
|
|
$I->seeResponseCodeIs(HttpCode::OK); |
197
|
|
|
$I->seeResponseIsJson(); |
198
|
|
|
$I->seeResponseMatchesOpenApiSchema(); |
199
|
|
|
|
200
|
|
|
$I->amSure('included resource has a relationship') |
201
|
|
|
->whenI() |
202
|
|
|
->seeIncludedResourceByTypeAndIdHasRelationshipByTypeAndId( |
|
|
|
|
203
|
|
|
WishlistsRestApiConfig::RESOURCE_WISHLIST_ITEMS, |
204
|
|
|
$productConcreteSku, |
205
|
|
|
ProductsRestApiConfig::RESOURCE_CONCRETE_PRODUCTS, |
206
|
|
|
$productConcreteSku, |
207
|
|
|
); |
208
|
|
|
|
209
|
|
|
$I->amSure('returned resource has include') |
210
|
|
|
->whenI() |
211
|
|
|
->seeIncludesContainsResourceByTypeAndId( |
212
|
|
|
ProductsRestApiConfig::RESOURCE_CONCRETE_PRODUCTS, |
213
|
|
|
$productConcreteSku, |
214
|
|
|
); |
215
|
|
|
|
216
|
|
|
$I->amSure('include has correct self-link') |
217
|
|
|
->whenI() |
218
|
|
|
->seeIncludedResourceByTypeAndIdHasSelfLink( |
219
|
|
|
ProductsRestApiConfig::RESOURCE_CONCRETE_PRODUCTS, |
220
|
|
|
$productConcreteSku, |
221
|
|
|
$I->buildProductConcreteUrl($productConcreteSku), |
222
|
|
|
); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* @depends loadFixtures |
227
|
|
|
* |
228
|
|
|
* @param \PyzTest\Glue\Wishlists\WishlistsApiTester $I |
229
|
|
|
* |
230
|
|
|
* @return void |
231
|
|
|
*/ |
232
|
|
|
public function requestWishlistByNotExistingWishlistUuid(WishlistsApiTester $I): void |
233
|
|
|
{ |
234
|
|
|
// Arrange |
235
|
|
|
$oauthResponseTransfer = $I->haveAuthorizationToGlue($this->fixtures->getCustomerTransfer()); |
236
|
|
|
$I->amBearerAuthenticated($oauthResponseTransfer->getAccessToken()); |
237
|
|
|
|
238
|
|
|
// Act |
239
|
|
|
$I->sendGET($I->buildWishlistUrl('NotExistingUuid')); |
240
|
|
|
|
241
|
|
|
// Assert |
242
|
|
|
$I->seeResponseCodeIs(HttpCode::NOT_FOUND); |
243
|
|
|
$I->seeResponseIsJson(); |
244
|
|
|
$I->seeResponseMatchesOpenApiSchema(); |
245
|
|
|
} |
246
|
|
|
} |
247
|
|
|
|