|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use app\fixtures\{OauthAccessTokensFixture, TransitionFixture}; |
|
4
|
|
|
use Codeception\{Example, Util\HttpCode}; |
|
5
|
|
|
use roaresearch\yii2\roa\test\AbstractResourceCest; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Cest to transition resource. |
|
9
|
|
|
* |
|
10
|
|
|
* @author Carlos (neverabe) Llamosas <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
class TransitionCest extends AbstractResourceCest |
|
13
|
|
|
{ |
|
14
|
|
|
protected function authToken(ApiTester $I) |
|
15
|
|
|
{ |
|
16
|
|
|
$I->amBearerAuthenticated(OauthAccessTokensFixture::SIMPLE_TOKEN); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @depends StageCest:fixtures |
|
21
|
|
|
*/ |
|
22
|
|
|
public function fixtures(ApiTester $I) |
|
23
|
|
|
{ |
|
24
|
|
|
$I->haveFixtures([ |
|
25
|
|
|
'transition' => [ |
|
26
|
|
|
'class' => TransitionFixture::class, |
|
27
|
|
|
'depends' => [], |
|
28
|
|
|
] |
|
29
|
|
|
]); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param ApiTester $I |
|
34
|
|
|
* @param Example $example |
|
35
|
|
|
* @dataprovider indexDataProvider |
|
36
|
|
|
* @depends fixtures |
|
37
|
|
|
* @before authToken |
|
38
|
|
|
*/ |
|
39
|
|
|
public function index(ApiTester $I, Example $example) |
|
40
|
|
|
{ |
|
41
|
|
|
$I->wantTo('Retrieve list of Transition records.'); |
|
42
|
|
|
$this->internalIndex($I, $example); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @return array<string,array> for test `index()`. |
|
47
|
|
|
*/ |
|
48
|
|
|
protected function indexDataProvider() |
|
49
|
|
|
{ |
|
50
|
|
|
return [ |
|
51
|
|
|
'list' => [ |
|
52
|
|
|
'urlParams' => [ |
|
53
|
|
|
'workflow_id' => 2, |
|
54
|
|
|
'stage_id' => 5, |
|
55
|
|
|
'expand' => 'sourceStage, targetStage, permissions' |
|
56
|
|
|
], |
|
57
|
|
|
'httpCode' => HttpCode::OK, |
|
58
|
|
|
'headers' => [ |
|
59
|
|
|
'X-Pagination-Total-Count' => 2, |
|
60
|
|
|
], |
|
61
|
|
|
], |
|
62
|
|
|
'not found workflow' => [ |
|
63
|
|
|
'urlParams' => [ |
|
64
|
|
|
'workflow_id' => 1, |
|
65
|
|
|
'stage_id' => 5 |
|
66
|
|
|
], |
|
67
|
|
|
'httpCode' => HttpCode::NOT_FOUND, |
|
68
|
|
|
], |
|
69
|
|
|
'not found stage' => [ |
|
70
|
|
|
'urlParams' => [ |
|
71
|
|
|
'workflow_id' => 2, |
|
72
|
|
|
'stage_id' => 10 |
|
73
|
|
|
], |
|
74
|
|
|
'httpCode' => HttpCode::NOT_FOUND, |
|
75
|
|
|
], |
|
76
|
|
|
'not found transition' => [ |
|
77
|
|
|
'url' => '/w1/workflow/2/stage/5/transition/1', |
|
78
|
|
|
'httpCode' => HttpCode::NOT_FOUND, |
|
79
|
|
|
], |
|
80
|
|
|
'filter by name' => [ |
|
81
|
|
|
'urlParams' => [ |
|
82
|
|
|
'workflow_id' => 2, |
|
83
|
|
|
'stage_id' => 5, |
|
84
|
|
|
'name' => 'Stage 2 to Stage 3' |
|
85
|
|
|
], |
|
86
|
|
|
'httpCode' => HttpCode::OK, |
|
87
|
|
|
'headers' => [ |
|
88
|
|
|
'X-Pagination-Total-Count' => 1, |
|
89
|
|
|
], |
|
90
|
|
|
], |
|
91
|
|
|
'rule created_by' => [ |
|
92
|
|
|
'urlParams' => [ |
|
93
|
|
|
'workflow_id' => 2, |
|
94
|
|
|
'stage_id' => 5, |
|
95
|
|
|
'created_by' => 'tra', |
|
96
|
|
|
], |
|
97
|
|
|
'httpCode' => HttpCode::UNPROCESSABLE_ENTITY, |
|
98
|
|
|
], |
|
99
|
|
|
]; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @param ApiTester $I |
|
104
|
|
|
* @param Example $example |
|
105
|
|
|
* @dataprovider viewDataProvider |
|
106
|
|
|
* @depends fixtures |
|
107
|
|
|
* @before authToken |
|
108
|
|
|
*/ |
|
109
|
|
|
public function view(ApiTester $I, Example $example) |
|
110
|
|
|
{ |
|
111
|
|
|
$I->wantTo('Retrieve Transition single record.'); |
|
112
|
|
|
$this->internalView($I, $example); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @return array<string,array<string,string>> data for test `view()`. |
|
117
|
|
|
*/ |
|
118
|
|
|
protected function viewDataProvider() |
|
119
|
|
|
{ |
|
120
|
|
|
return [ |
|
121
|
|
|
'single record' => [ |
|
122
|
|
|
'url' => '/w1/workflow/1/stage/1/transition/2', |
|
123
|
|
|
'httpCode' => HttpCode::OK, |
|
124
|
|
|
], |
|
125
|
|
|
'transition not found' => [ |
|
126
|
|
|
'url' => '/w1/workflow/1/stage/2/transition/2', |
|
127
|
|
|
'httpCode' => HttpCode::NOT_FOUND, |
|
128
|
|
|
], |
|
129
|
|
|
'stage not found' => [ |
|
130
|
|
|
'url' => '/w1/workflow/1/stage/10/transition/2', |
|
131
|
|
|
'httpCode' => HttpCode::NOT_FOUND, |
|
132
|
|
|
], |
|
133
|
|
|
'workflow not found' => [ |
|
134
|
|
|
'url' => '/w1/workflow/10/stage/1/transition/2', |
|
135
|
|
|
'httpCode' => HttpCode::NOT_FOUND, |
|
136
|
|
|
], |
|
137
|
|
|
]; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @param ApiTester $I |
|
142
|
|
|
* @param Example $example |
|
143
|
|
|
* @dataprovider createDataProvider |
|
144
|
|
|
* @depends fixtures |
|
145
|
|
|
* @before authToken |
|
146
|
|
|
*/ |
|
147
|
|
|
public function create(ApiTester $I, Example $example) |
|
148
|
|
|
{ |
|
149
|
|
|
$I->wantTo('Create a Transition record.'); |
|
150
|
|
|
$this->internalCreate($I, $example); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* @return array<string,array> data for test `create()`. |
|
155
|
|
|
*/ |
|
156
|
|
|
protected function createDataProvider() |
|
157
|
|
|
{ |
|
158
|
|
|
return [ |
|
159
|
|
|
'create transition' => [ |
|
160
|
|
|
'urlParams' => [ |
|
161
|
|
|
'workflow_id' => 1, |
|
162
|
|
|
'stage_id' => 1 |
|
163
|
|
|
], |
|
164
|
|
|
'data' => [ |
|
165
|
|
|
'source_stage_id' => 1, |
|
166
|
|
|
'target_stage_id' => 3, |
|
167
|
|
|
'name' => 'new Transition' |
|
168
|
|
|
], |
|
169
|
|
|
'httpCode' => HttpCode::CREATED, |
|
170
|
|
|
], |
|
171
|
|
|
'required data' => [ |
|
172
|
|
|
'urlParams' => [ |
|
173
|
|
|
'workflow_id' => 1, |
|
174
|
|
|
'stage_id' => 1 |
|
175
|
|
|
], |
|
176
|
|
|
'data' => [ |
|
177
|
|
|
'source_stage_id' => 2, |
|
178
|
|
|
'target_stage_id' => 3, |
|
179
|
|
|
], |
|
180
|
|
|
'httpCode' => HttpCode::UNPROCESSABLE_ENTITY, |
|
181
|
|
|
'validationErrors' => [ |
|
182
|
|
|
'name' => 'Transition Name cannot be blank.' |
|
183
|
|
|
], |
|
184
|
|
|
], |
|
185
|
|
|
'required data 2' => [ |
|
186
|
|
|
'urlParams' => [ |
|
187
|
|
|
'workflow_id' => 1, |
|
188
|
|
|
'stage_id' => 1 |
|
189
|
|
|
], |
|
190
|
|
|
'data' => [ |
|
191
|
|
|
'source_stage_id' => 1, |
|
192
|
|
|
'target_stage_id' => 4 |
|
193
|
|
|
], |
|
194
|
|
|
'httpCode' => HttpCode::UNPROCESSABLE_ENTITY, |
|
195
|
|
|
'validationErrors' => [ |
|
196
|
|
|
'name' => 'Transition Name cannot be blank.', |
|
197
|
|
|
'target_stage_id' => 'The stages are not associated to the same workflow.' |
|
198
|
|
|
], |
|
199
|
|
|
], |
|
200
|
|
|
'workflow not found' => [ |
|
201
|
|
|
'urlParams' => [ |
|
202
|
|
|
'workflow_id' => 10, |
|
203
|
|
|
'stage_id' => 1 |
|
204
|
|
|
], |
|
205
|
|
|
'data' => [ |
|
206
|
|
|
'source_stage_id' => 1, |
|
207
|
|
|
'target_stage_id' => 4 |
|
208
|
|
|
], |
|
209
|
|
|
'httpCode' => HttpCode::NOT_FOUND, |
|
210
|
|
|
], |
|
211
|
|
|
'stage not found' => [ |
|
212
|
|
|
'urlParams' => [ |
|
213
|
|
|
'workflow_id' => 1, |
|
214
|
|
|
'stage_id' => 19 |
|
215
|
|
|
], |
|
216
|
|
|
'data' => [ |
|
217
|
|
|
'source_stage_id' => 1, |
|
218
|
|
|
'target_stage_id' => 4 |
|
219
|
|
|
], |
|
220
|
|
|
'httpCode' => HttpCode::NOT_FOUND, |
|
221
|
|
|
], |
|
222
|
|
|
'unique source target' => [ |
|
223
|
|
|
'urlParams' => [ |
|
224
|
|
|
'workflow_id' => 1, |
|
225
|
|
|
'stage_id' => 1 |
|
226
|
|
|
], |
|
227
|
|
|
'data' => [ |
|
228
|
|
|
'source_stage_id' => 1, |
|
229
|
|
|
'target_stage_id' => 2, |
|
230
|
|
|
'name' => 'not unique' |
|
231
|
|
|
], |
|
232
|
|
|
'httpCode' => HttpCode::UNPROCESSABLE_ENTITY, |
|
233
|
|
|
'validationErrors' => [ |
|
234
|
|
|
'target_stage_id' => 'Target already in use for the source stage.' |
|
235
|
|
|
], |
|
236
|
|
|
], |
|
237
|
|
|
'unique source name' => [ |
|
238
|
|
|
'urlParams' => [ |
|
239
|
|
|
'workflow_id' => 1, |
|
240
|
|
|
'stage_id' => 1 |
|
241
|
|
|
], |
|
242
|
|
|
'data' => [ |
|
243
|
|
|
'source_stage_id' => 1, |
|
244
|
|
|
'target_stage_id' => 3, |
|
245
|
|
|
'name' => 'Transition 1 Stage 1 to Stage 2 Wf 1' |
|
246
|
|
|
], |
|
247
|
|
|
'httpCode' => HttpCode::UNPROCESSABLE_ENTITY, |
|
248
|
|
|
'validationErrors' => [ |
|
249
|
|
|
'name' => 'Name already used for the source stage.' |
|
250
|
|
|
], |
|
251
|
|
|
], |
|
252
|
|
|
]; |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
/** |
|
256
|
|
|
* @param ApiTester $I |
|
257
|
|
|
* @param Example $example |
|
258
|
|
|
* @dataprovider updateDataProvider |
|
259
|
|
|
* @depends fixtures |
|
260
|
|
|
* @before authToken |
|
261
|
|
|
*/ |
|
262
|
|
|
public function update(ApiTester $I, Example $example) |
|
263
|
|
|
{ |
|
264
|
|
|
$I->wantTo('Update a Transition record.'); |
|
265
|
|
|
$this->internalUpdate($I, $example); |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
/** |
|
269
|
|
|
* @return array<string,array<string,string|array<string,string>>> data for test `update()`. |
|
270
|
|
|
*/ |
|
271
|
|
|
protected function updateDataProvider() |
|
272
|
|
|
{ |
|
273
|
|
|
return [ |
|
274
|
|
|
'update transition' => [ |
|
275
|
|
|
'url' => '/w1/workflow/1/stage/1/transition/2', |
|
276
|
|
|
'data' => ['name' => 'update transition'], |
|
277
|
|
|
'httpCode' => HttpCode::OK, |
|
278
|
|
|
], |
|
279
|
|
|
'to short' => [ |
|
280
|
|
|
'url' => '/w1/workflow/1/stage/1/transition/2', |
|
281
|
|
|
'data' => ['name' => 'tr'], |
|
282
|
|
|
'httpCode' => HttpCode::UNPROCESSABLE_ENTITY, |
|
283
|
|
|
'validationErrors' => [ |
|
284
|
|
|
'name' => 'Transition Name should contain at least 6 characters.' |
|
285
|
|
|
], |
|
286
|
|
|
], |
|
287
|
|
|
]; |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
/** |
|
291
|
|
|
* @param ApiTester $I |
|
292
|
|
|
* @param Example $example |
|
293
|
|
|
* @dataprovider deleteDataProvider |
|
294
|
|
|
* @depends fixtures |
|
295
|
|
|
* @before authToken |
|
296
|
|
|
*/ |
|
297
|
|
|
public function delete(ApiTester $I, Example $example) |
|
298
|
|
|
{ |
|
299
|
|
|
$I->wantTo('Delete a Transition record.'); |
|
300
|
|
|
$this->internalDelete($I, $example); |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
/** |
|
304
|
|
|
* @return array<string,array<string,string|array<string,string>>> data for test `delete()`. |
|
305
|
|
|
*/ |
|
306
|
|
|
protected function deleteDataProvider() |
|
307
|
|
|
{ |
|
308
|
|
|
return [ |
|
309
|
|
|
'workflow not found' => [ |
|
310
|
|
|
'url' => '/w1/workflow/10/stage/1/transition/2', |
|
311
|
|
|
'httpCode' => HttpCode::NOT_FOUND, |
|
312
|
|
|
], |
|
313
|
|
|
'stage not found' => [ |
|
314
|
|
|
'url' => '/w1/workflow/1/stage/10/transition/2', |
|
315
|
|
|
'httpCode' => HttpCode::NOT_FOUND, |
|
316
|
|
|
], |
|
317
|
|
|
'transition not found' => [ |
|
318
|
|
|
'url' => '/w1/workflow/1/stage/1/transition/10', |
|
319
|
|
|
'httpCode' => HttpCode::NOT_FOUND, |
|
320
|
|
|
], |
|
321
|
|
|
'delete transition 1-3' => [ |
|
322
|
|
|
'url' => '/w1/workflow/1/stage/1/transition/3', |
|
323
|
|
|
'httpCode' => HttpCode::NO_CONTENT, |
|
324
|
|
|
], |
|
325
|
|
|
'not found' => [ |
|
326
|
|
|
'url' => '/w1/workflow/1/stage/1/transition/3', |
|
327
|
|
|
'httpCode' => HttpCode::NOT_FOUND, |
|
328
|
|
|
'validationErrors' => [ |
|
329
|
|
|
'name' => 'The record "3" does not exists.' |
|
330
|
|
|
], |
|
331
|
|
|
], |
|
332
|
|
|
]; |
|
333
|
|
|
} |
|
334
|
|
|
/** |
|
335
|
|
|
* @inheritdoc |
|
336
|
|
|
*/ |
|
337
|
|
|
protected function recordJsonType(): array |
|
338
|
|
|
{ |
|
339
|
|
|
return [ |
|
340
|
|
|
'source_stage_id' => 'integer:>0', |
|
341
|
|
|
'target_stage_id' => 'integer:>0', |
|
342
|
|
|
'name' => 'string', |
|
343
|
|
|
]; |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
/** |
|
347
|
|
|
* @inheritdoc |
|
348
|
|
|
*/ |
|
349
|
|
|
protected function getRoutePattern(): string |
|
350
|
|
|
{ |
|
351
|
|
|
return 'w1/workflow/<workflow_id:\d+>/stage/<stage_id:\d+>/transition'; |
|
352
|
|
|
} |
|
353
|
|
|
} |
|
354
|
|
|
|