|
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\Fixtures; |
|
11
|
|
|
|
|
12
|
|
|
use Generated\Shared\DataBuilder\CompanyRoleCollectionBuilder; |
|
13
|
|
|
use Generated\Shared\DataBuilder\PermissionCollectionBuilder; |
|
14
|
|
|
use Generated\Shared\DataBuilder\QuoteBuilder; |
|
15
|
|
|
use Generated\Shared\Transfer\CompanyBusinessUnitTransfer; |
|
16
|
|
|
use Generated\Shared\Transfer\CompanyRoleTransfer; |
|
17
|
|
|
use Generated\Shared\Transfer\CompanyTransfer; |
|
18
|
|
|
use Generated\Shared\Transfer\CompanyUnitAddressCollectionTransfer; |
|
19
|
|
|
use Generated\Shared\Transfer\CompanyUnitAddressTransfer; |
|
20
|
|
|
use Generated\Shared\Transfer\CompanyUserTransfer; |
|
21
|
|
|
use Generated\Shared\Transfer\CustomerTransfer; |
|
22
|
|
|
use Generated\Shared\Transfer\ItemTransfer; |
|
23
|
|
|
use Generated\Shared\Transfer\OrderTransfer; |
|
24
|
|
|
use Generated\Shared\Transfer\PermissionCollectionTransfer; |
|
25
|
|
|
use Generated\Shared\Transfer\SaveOrderTransfer; |
|
26
|
|
|
use Generated\Shared\Transfer\SspAssetBusinessUnitAssignmentTransfer; |
|
27
|
|
|
use Generated\Shared\Transfer\SspAssetTransfer; |
|
28
|
|
|
use Generated\Shared\Transfer\SspInquiryTransfer; |
|
29
|
|
|
use Generated\Shared\Transfer\StateMachineItemStateTransfer; |
|
30
|
|
|
use Generated\Shared\Transfer\StateMachineProcessTransfer; |
|
31
|
|
|
use PyzTest\Glue\SelfServicePortal\SelfServicePortalApiTester; |
|
32
|
|
|
use SprykerFeature\Shared\SelfServicePortal\Plugin\Permission\CreateSspInquiryPermissionPlugin; |
|
33
|
|
|
use SprykerFeature\Shared\SelfServicePortal\Plugin\Permission\ViewBusinessUnitSspInquiryPermissionPlugin; |
|
34
|
|
|
use SprykerFeature\Shared\SelfServicePortal\Plugin\Permission\ViewCompanySspInquiryPermissionPlugin; |
|
35
|
|
|
use SprykerTest\Shared\Testify\Fixtures\FixturesBuilderInterface; |
|
36
|
|
|
use SprykerTest\Shared\Testify\Fixtures\FixturesContainerInterface; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Auto-generated group annotations |
|
40
|
|
|
* |
|
41
|
|
|
* @group PyzTest |
|
42
|
|
|
* @group Glue |
|
43
|
|
|
* @group SelfServicePortal |
|
44
|
|
|
* @group RestApi |
|
45
|
|
|
* @group SspInquiriesRestApiCest |
|
46
|
|
|
* Add your own group annotations below this line |
|
47
|
|
|
* @group EndToEnd |
|
48
|
|
|
*/ |
|
49
|
|
|
class SspInquiriesRestApiFixtures implements FixturesBuilderInterface, FixturesContainerInterface |
|
50
|
|
|
{ |
|
51
|
|
|
protected const TEST_USERNAME = 'SspInquiriesRestApiFixtures'; |
|
52
|
|
|
|
|
53
|
|
|
protected const TEST_PASSWORD = 'change123'; |
|
54
|
|
|
|
|
55
|
|
|
protected const TEST_COMPANY_NAME = 'Test Inquiries Company'; |
|
56
|
|
|
|
|
57
|
|
|
protected const PRICE_MODE_GROSS = 'GROSS_MODE'; |
|
58
|
|
|
|
|
59
|
|
|
protected const STATE_MACHINE_NAME = 'DummyPayment01'; |
|
60
|
|
|
|
|
61
|
|
|
public const PERMISSION_PLUGINS = [ |
|
62
|
|
|
ViewBusinessUnitSspInquiryPermissionPlugin::class, |
|
63
|
|
|
ViewCompanySspInquiryPermissionPlugin::class, |
|
64
|
|
|
CreateSspInquiryPermissionPlugin::class, |
|
65
|
|
|
]; |
|
66
|
|
|
|
|
67
|
|
|
protected CustomerTransfer $customerTransfer; |
|
68
|
|
|
|
|
69
|
|
|
protected CompanyTransfer $companyTransfer; |
|
70
|
|
|
|
|
71
|
|
|
protected CompanyUserTransfer $companyUserTransfer; |
|
72
|
|
|
|
|
73
|
|
|
protected SspInquiryTransfer $inquiryTransfer; |
|
74
|
|
|
|
|
75
|
|
|
protected SspAssetTransfer $assetTransfer; |
|
76
|
|
|
|
|
77
|
|
|
protected SaveOrderTransfer $saveOrderTransfer; |
|
78
|
|
|
|
|
79
|
|
|
protected CompanyBusinessUnitTransfer $companyBusinessUnitTransfer; |
|
80
|
|
|
|
|
81
|
|
|
protected CompanyUnitAddressTransfer $companyUnitAddressTransfer; |
|
82
|
|
|
|
|
83
|
|
|
protected PermissionCollectionTransfer $permissionCollectionTransfer; |
|
84
|
|
|
|
|
85
|
|
|
protected SspInquiryTransfer $inquiryWithAssetTransfer; |
|
86
|
|
|
|
|
87
|
|
|
protected SspInquiryTransfer $inquiryWithOrderTransfer; |
|
88
|
|
|
|
|
89
|
|
|
public function buildFixtures(SelfServicePortalApiTester $I): FixturesContainerInterface |
|
90
|
|
|
{ |
|
91
|
|
|
$this->createCompany($I); |
|
92
|
|
|
$this->createCustomer($I); |
|
93
|
|
|
$this->createCompanyBusinessUnit($I); |
|
94
|
|
|
$this->createCompanyUser($I); |
|
95
|
|
|
$this->createAsset($I); |
|
96
|
|
|
$this->createOrderWithProductConcretes($I); |
|
97
|
|
|
$this->createInquiries($I); |
|
98
|
|
|
|
|
99
|
|
|
return $this; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function getCustomerTransfer(): CustomerTransfer |
|
103
|
|
|
{ |
|
104
|
|
|
return $this->customerTransfer; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function getCompanyTransfer(): CompanyTransfer |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->companyTransfer; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
public function getCompanyUserTransfer(): CompanyUserTransfer |
|
113
|
|
|
{ |
|
114
|
|
|
return $this->companyUserTransfer; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
public function getInquiryTransfer(): SspInquiryTransfer |
|
118
|
|
|
{ |
|
119
|
|
|
return $this->inquiryTransfer; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function getInquiryWithAssetTransfer(): SspInquiryTransfer |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->inquiryWithAssetTransfer; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
public function getInquiryWithOrderTransfer(): SspInquiryTransfer |
|
128
|
|
|
{ |
|
129
|
|
|
return $this->inquiryWithOrderTransfer; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
public function getAssetTransfer(): SspAssetTransfer |
|
133
|
|
|
{ |
|
134
|
|
|
return $this->assetTransfer; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
public function getSaveOrderTransfer(): SaveOrderTransfer |
|
138
|
|
|
{ |
|
139
|
|
|
return $this->saveOrderTransfer; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
protected function createCompany(SelfServicePortalApiTester $I): void |
|
143
|
|
|
{ |
|
144
|
|
|
$this->companyTransfer = $I->haveCompany([ |
|
145
|
|
|
CompanyTransfer::NAME => static::TEST_COMPANY_NAME, |
|
146
|
|
|
CompanyTransfer::STATUS => 'approved', |
|
147
|
|
|
CompanyTransfer::IS_ACTIVE => true, |
|
148
|
|
|
]); |
|
149
|
|
|
|
|
150
|
|
|
$this->companyUnitAddressTransfer = $I->haveCompanyUnitAddress([ |
|
151
|
|
|
CompanyUnitAddressTransfer::FK_COMPANY => $this->companyTransfer->getIdCompany(), |
|
152
|
|
|
]); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
protected function createCustomer(SelfServicePortalApiTester $I): void |
|
156
|
|
|
{ |
|
157
|
|
|
$customerTransfer = $I->haveCustomer([ |
|
158
|
|
|
CustomerTransfer::USERNAME => static::TEST_USERNAME, |
|
159
|
|
|
CustomerTransfer::PASSWORD => static::TEST_PASSWORD, |
|
160
|
|
|
CustomerTransfer::NEW_PASSWORD => static::TEST_PASSWORD, |
|
161
|
|
|
]); |
|
162
|
|
|
|
|
163
|
|
|
$this->customerTransfer = $I->confirmCustomer($customerTransfer); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
protected function createCompanyUser(SelfServicePortalApiTester $I): void |
|
167
|
|
|
{ |
|
168
|
|
|
$this->companyUserTransfer = $I->haveCompanyUser([ |
|
169
|
|
|
CompanyUserTransfer::CUSTOMER => $this->customerTransfer, |
|
170
|
|
|
CompanyUserTransfer::FK_COMPANY => $this->companyTransfer->getIdCompany(), |
|
171
|
|
|
CompanyUserTransfer::FK_COMPANY_BUSINESS_UNIT => $this->companyBusinessUnitTransfer->getIdCompanyBusinessUnit(), |
|
172
|
|
|
]); |
|
173
|
|
|
|
|
174
|
|
|
$this->permissionCollectionTransfer = (new PermissionCollectionBuilder())->build(); |
|
175
|
|
|
foreach (static::PERMISSION_PLUGINS as $permissionPlugin) { |
|
176
|
|
|
$permissionTransfer = $I->havePermission(new $permissionPlugin()); |
|
177
|
|
|
$this->permissionCollectionTransfer->addPermission($permissionTransfer); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
$companyRoleTransfer = $I->haveCompanyRole([ |
|
181
|
|
|
CompanyRoleTransfer::FK_COMPANY => $this->companyTransfer->getIdCompany(), |
|
182
|
|
|
CompanyRoleTransfer::PERMISSION_COLLECTION => $this->permissionCollectionTransfer, |
|
183
|
|
|
]); |
|
184
|
|
|
|
|
185
|
|
|
$companyRoleCollectionTransfer = (new CompanyRoleCollectionBuilder())->build() |
|
186
|
|
|
->addRole($companyRoleTransfer); |
|
187
|
|
|
|
|
188
|
|
|
$this->companyUserTransfer->setCompanyRoleCollection($companyRoleCollectionTransfer); |
|
189
|
|
|
|
|
190
|
|
|
$I->assignCompanyRolesToCompanyUser($this->companyUserTransfer); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
protected function createCompanyBusinessUnit(SelfServicePortalApiTester $I): void |
|
194
|
|
|
{ |
|
195
|
|
|
$this->companyBusinessUnitTransfer = $I->haveCompanyBusinessUnit([ |
|
196
|
|
|
CompanyBusinessUnitTransfer::FK_COMPANY => $this->companyTransfer->getIdCompany(), |
|
197
|
|
|
CompanyBusinessUnitTransfer::ADDRESS_COLLECTION => (new CompanyUnitAddressCollectionTransfer()) |
|
198
|
|
|
->addCompanyUnitAddress($this->companyUnitAddressTransfer), |
|
199
|
|
|
]); |
|
200
|
|
|
|
|
201
|
|
|
$I->haveCompanyUnitAddressToCompanyBusinessUnitRelation($this->companyBusinessUnitTransfer); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
protected function createInquiries(SelfServicePortalApiTester $I): void |
|
205
|
|
|
{ |
|
206
|
|
|
$sspInquiryStateMachineProcess = $I->haveStateMachineProcess([ |
|
207
|
|
|
StateMachineProcessTransfer::STATE_MACHINE_NAME => 'test_ssp_inquiry', |
|
208
|
|
|
]); |
|
209
|
|
|
|
|
210
|
|
|
$I->haveStateMachineItemState([ |
|
211
|
|
|
StateMachineItemStateTransfer::FK_STATE_MACHINE_PROCESS => $sspInquiryStateMachineProcess->getIdStateMachineProcess(), |
|
212
|
|
|
StateMachineItemStateTransfer::NAME => 'test_initial_state', |
|
213
|
|
|
]); |
|
214
|
|
|
|
|
215
|
|
|
$this->inquiryTransfer = $I->haveSspInquiry([ |
|
216
|
|
|
SspInquiryTransfer::SUBJECT => 'Test inquiry subject 1', |
|
217
|
|
|
SspInquiryTransfer::DESCRIPTION => 'This is a test inquiry description 1', |
|
218
|
|
|
SspInquiryTransfer::TYPE => 'general', |
|
219
|
|
|
SspInquiryTransfer::STATUS => 'test_initial_state', |
|
220
|
|
|
SspInquiryTransfer::COMPANY_USER => $this->companyUserTransfer, |
|
221
|
|
|
]); |
|
222
|
|
|
|
|
223
|
|
|
$this->inquiryWithAssetTransfer = $I->haveSspInquiry([ |
|
224
|
|
|
SspInquiryTransfer::SUBJECT => 'Test inquiry subject 2', |
|
225
|
|
|
SspInquiryTransfer::DESCRIPTION => 'This is a test inquiry description 2', |
|
226
|
|
|
SspInquiryTransfer::TYPE => 'ssp_asset', |
|
227
|
|
|
SspInquiryTransfer::STATUS => 'test_initial_state', |
|
228
|
|
|
SspInquiryTransfer::SSP_ASSET => $this->assetTransfer, |
|
229
|
|
|
SspInquiryTransfer::COMPANY_USER => $this->companyUserTransfer, |
|
230
|
|
|
]); |
|
231
|
|
|
|
|
232
|
|
|
$this->inquiryWithOrderTransfer = $I->haveSspInquiry([ |
|
233
|
|
|
SspInquiryTransfer::SUBJECT => 'Test inquiry subject 3', |
|
234
|
|
|
SspInquiryTransfer::DESCRIPTION => 'This is a test inquiry description 3', |
|
235
|
|
|
SspInquiryTransfer::TYPE => 'order', |
|
236
|
|
|
SspInquiryTransfer::STATUS => 'test_initial_state', |
|
237
|
|
|
SspInquiryTransfer::COMPANY_USER => $this->companyUserTransfer, |
|
238
|
|
|
SspInquiryTransfer::ORDER => (new OrderTransfer())->setIdSalesOrder($this->saveOrderTransfer->getIdSalesOrder()) |
|
239
|
|
|
->setOrderReference($this->saveOrderTransfer->getOrderReference()), |
|
240
|
|
|
]); |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
protected function createAsset(SelfServicePortalApiTester $I): void |
|
244
|
|
|
{ |
|
245
|
|
|
$this->assetTransfer = $I->haveAsset([ |
|
246
|
|
|
SspAssetTransfer::REFERENCE => 'ASSET-00100001123', |
|
247
|
|
|
SspAssetTransfer::EXTERNAL_IMAGE_URL => 'https://example.com/asset.pdf', |
|
248
|
|
|
SspAssetTransfer::COMPANY_BUSINESS_UNIT => $this->companyBusinessUnitTransfer, |
|
249
|
|
|
SspAssetTransfer::SERIAL_NUMBER => 'test-serial-123', |
|
250
|
|
|
SspAssetTransfer::NOTE => 'Test asset for inquiry testing', |
|
251
|
|
|
SspAssetTransfer::BUSINESS_UNIT_ASSIGNMENTS => [ |
|
252
|
|
|
[SspAssetBusinessUnitAssignmentTransfer::COMPANY_BUSINESS_UNIT => $this->companyBusinessUnitTransfer], |
|
253
|
|
|
], |
|
254
|
|
|
]); |
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
|
|
protected function createOrderWithProductConcretes(SelfServicePortalApiTester $I): void |
|
258
|
|
|
{ |
|
259
|
|
|
$product1Transfer = $I->haveProductWithPriceAndStock(); |
|
260
|
|
|
$product2Transfer = $I->haveProductWithPriceAndStock(); |
|
261
|
|
|
$quoteTransfer = (new QuoteBuilder()) |
|
262
|
|
|
->withCustomer([CustomerTransfer::CUSTOMER_REFERENCE => $this->customerTransfer->getCustomerReference()]) |
|
263
|
|
|
->withItem([ |
|
264
|
|
|
ItemTransfer::SKU => $product1Transfer->getSkuOrFail(), |
|
265
|
|
|
ItemTransfer::QUANTITY => 1, |
|
266
|
|
|
]) |
|
267
|
|
|
->withItem([ |
|
268
|
|
|
ItemTransfer::SKU => $product2Transfer->getSkuOrFail(), |
|
269
|
|
|
ItemTransfer::QUANTITY => 2, |
|
270
|
|
|
]) |
|
271
|
|
|
->withTotals() |
|
272
|
|
|
->withShippingAddress() |
|
273
|
|
|
->withBillingAddress() |
|
274
|
|
|
->withCurrency() |
|
275
|
|
|
->withPayment() |
|
276
|
|
|
->build(); |
|
277
|
|
|
|
|
278
|
|
|
$quoteTransfer->setPriceMode(static::PRICE_MODE_GROSS); |
|
279
|
|
|
|
|
280
|
|
|
$this->saveOrderTransfer = $I->haveOrderFromQuote($quoteTransfer, static::STATE_MACHINE_NAME); |
|
281
|
|
|
} |
|
282
|
|
|
} |
|
283
|
|
|
|