1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use app\fixtures\{OauthAccessTokensFixture, WorkflowFixture}; |
4
|
|
|
use Codeception\{Example, Util\HttpCode}; |
5
|
|
|
use roaresearch\yii2\roa\test\AbstractResourceCest; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Cest to workflow resource. |
9
|
|
|
* |
10
|
|
|
* @author Carlos (neverabe) Llamosas <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class WorkflowCest extends AbstractResourceCest |
13
|
|
|
{ |
14
|
|
|
protected function authToken(ApiTester $I) |
15
|
|
|
{ |
16
|
|
|
$I->amBearerAuthenticated(OauthAccessTokensFixture::SIMPLE_TOKEN); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function fixtures(ApiTester $I) |
20
|
|
|
{ |
21
|
|
|
$I->haveFixtures([ |
22
|
|
|
'access_tokens' => OauthAccessTokensFixture::class, |
23
|
|
|
'workflow' => WorkflowFixture::class, |
24
|
|
|
]); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param ApiTester $I |
29
|
|
|
* @param Example $example |
30
|
|
|
* @dataprovider indexDataProvider |
31
|
|
|
* @depends fixtures |
32
|
|
|
* @before authToken |
33
|
|
|
*/ |
34
|
|
|
public function index(ApiTester $I, Example $example) |
35
|
|
|
{ |
36
|
|
|
$I->wantTo('Retrieve list of Workflow records.'); |
37
|
|
|
$this->internalIndex($I, $example); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return array<string,array> for test `index()`. |
42
|
|
|
*/ |
43
|
|
|
protected function indexDataProvider() |
44
|
|
|
{ |
45
|
|
|
return [ |
46
|
|
|
'list' => [ |
47
|
|
|
'httpCode' => HttpCode::OK, |
48
|
|
|
], |
49
|
|
|
'filter by name' => [ |
50
|
|
|
'urlParams' => [ |
51
|
|
|
'name' => 'workflow 2', |
52
|
|
|
'expand' => 'stages' |
53
|
|
|
], |
54
|
|
|
'httpCode' => HttpCode::OK, |
55
|
|
|
'headers' => [ |
56
|
|
|
'X-Pagination-Total-Count' => 1, |
57
|
|
|
], |
58
|
|
|
], |
59
|
|
|
'filter by author' => [ |
60
|
|
|
'urlParams' => ['created_by' => 1], |
61
|
|
|
'httpCode' => HttpCode::OK, |
62
|
|
|
'headers' => [ |
63
|
|
|
'X-Pagination-Total-Count' => 2, |
64
|
|
|
], |
65
|
|
|
], |
66
|
|
|
'rule created_by' => [ |
67
|
|
|
'urlParams' => [ |
68
|
|
|
'created_by' => 'wo', |
69
|
|
|
], |
70
|
|
|
'httpCode' => HttpCode::UNPROCESSABLE_ENTITY, |
71
|
|
|
], |
72
|
|
|
]; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param ApiTester $I |
77
|
|
|
* @param Example $example |
78
|
|
|
* @dataprovider viewDataProvider |
79
|
|
|
* @depends StageCest:fixtures |
80
|
|
|
* @before authToken |
81
|
|
|
*/ |
82
|
|
|
public function view(ApiTester $I, Example $example) |
83
|
|
|
{ |
84
|
|
|
$I->wantTo('Retrieve Workflow single record.'); |
85
|
|
|
$this->internalView($I, $example); |
86
|
|
|
if (isset($example['response'])) { |
87
|
|
|
$I->seeResponseContainsJson($example['response']); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return array[] data for test `view()`. |
93
|
|
|
*/ |
94
|
|
|
protected function viewDataProvider() |
95
|
|
|
{ |
96
|
|
|
return [ |
97
|
|
|
'expand stages' => [ |
98
|
|
|
'urlParams' => [ |
99
|
|
|
'id' => '1', |
100
|
|
|
'expand' => 'stages, totalStages, detailStages' |
101
|
|
|
], |
102
|
|
|
'httpCode' => HttpCode::OK, |
103
|
|
|
'response' => [ |
104
|
|
|
'_embedded' => [ |
105
|
|
|
'stages' => [ |
106
|
|
|
['id' => 1], |
107
|
|
|
], |
108
|
|
|
'totalStages' => 3, |
109
|
|
|
], |
110
|
|
|
], |
111
|
|
|
], |
112
|
|
|
'field total stages' => [ |
113
|
|
|
'urlParams' => [ |
114
|
|
|
'id' => '1', |
115
|
|
|
'fields' => 'id,name' |
116
|
|
|
], |
117
|
|
|
'httpCode' => HttpCode::OK, |
118
|
|
|
'response' => [ |
119
|
|
|
'id' => 1, |
120
|
|
|
'name' => 'workflow 1', |
121
|
|
|
], |
122
|
|
|
], |
123
|
|
|
]; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @param ApiTester $I |
128
|
|
|
* @param Example $example |
129
|
|
|
* @dataprovider createDataProvider |
130
|
|
|
* @depends fixtures |
131
|
|
|
* @before authToken |
132
|
|
|
*/ |
133
|
|
|
public function create(ApiTester $I, Example $example) |
134
|
|
|
{ |
135
|
|
|
$I->wantTo('Create a Workflow record.'); |
136
|
|
|
$this->internalCreate($I, $example); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @return array<string,array<string,array<string,string>>> data for test `create()`. |
141
|
|
|
*/ |
142
|
|
|
protected function createDataProvider() |
143
|
|
|
{ |
144
|
|
|
return [ |
145
|
|
|
'create workflow 3' => [ |
146
|
|
|
'data' => ['name' => 'workflow 3'], |
147
|
|
|
'httpCode' => HttpCode::CREATED, |
148
|
|
|
], |
149
|
|
|
'unique' => [ |
150
|
|
|
'data' => ['name' => 'workflow 3'], |
151
|
|
|
'httpCode' => HttpCode::UNPROCESSABLE_ENTITY, |
152
|
|
|
'validationErrors' => [ |
153
|
|
|
'name' => 'Workflow name "workflow 3" has already been taken.' |
154
|
|
|
], |
155
|
|
|
], |
156
|
|
|
'to short' => [ |
157
|
|
|
'data' => ['name' => 'wo'], |
158
|
|
|
'httpCode' => HttpCode::UNPROCESSABLE_ENTITY, |
159
|
|
|
'validationErrors' => [ |
160
|
|
|
'name' => 'Workflow name should contain at least 6 characters.' |
161
|
|
|
], |
162
|
|
|
], |
163
|
|
|
'not blank' => [ |
164
|
|
|
'httpCode' => HttpCode::UNPROCESSABLE_ENTITY, |
165
|
|
|
'validationErrors' => [ |
166
|
|
|
'name' => 'Workflow name cannot be blank.' |
167
|
|
|
], |
168
|
|
|
], |
169
|
|
|
]; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @param ApiTester $I |
174
|
|
|
* @param Example $example |
175
|
|
|
* @dataprovider updateDataProvider |
176
|
|
|
* @depends fixtures |
177
|
|
|
* @before authToken |
178
|
|
|
*/ |
179
|
|
|
public function update(ApiTester $I, Example $example) |
180
|
|
|
{ |
181
|
|
|
$I->wantTo('Update a Workflow record.'); |
182
|
|
|
$this->internalUpdate($I, $example); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @return array[] data for test `update()`. |
187
|
|
|
*/ |
188
|
|
|
protected function updateDataProvider() |
189
|
|
|
{ |
190
|
|
|
return [ |
191
|
|
|
'update workflow 1' => [ |
192
|
|
|
'urlParams' => ['id' => '1'], |
193
|
|
|
'data' => ['name' => 'workflow 7'], |
194
|
|
|
'httpCode' => HttpCode::OK, |
195
|
|
|
], |
196
|
|
|
'to short' => [ |
197
|
|
|
'urlParams' => ['id' => '1'], |
198
|
|
|
'data' => ['name' => 'wo'], |
199
|
|
|
'httpCode' => HttpCode::UNPROCESSABLE_ENTITY, |
200
|
|
|
'validationErrors' => [ |
201
|
|
|
'name' => 'Workflow name should contain at least 6 characters.' |
202
|
|
|
], |
203
|
|
|
], |
204
|
|
|
]; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @param ApiTester $I |
209
|
|
|
* @param Example $example |
210
|
|
|
* @dataprovider deleteDataProvider |
211
|
|
|
* @depends fixtures |
212
|
|
|
* @before authToken |
213
|
|
|
*/ |
214
|
|
|
public function delete(ApiTester $I, Example $example) |
215
|
|
|
{ |
216
|
|
|
$I->wantTo('Delete a Workflow record.'); |
217
|
|
|
$this->internalDelete($I, $example); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* @return array[] data for test `delete()`. |
222
|
|
|
*/ |
223
|
|
|
protected function deleteDataProvider() |
224
|
|
|
{ |
225
|
|
|
return [ |
226
|
|
|
'delete workflow 1' => [ |
227
|
|
|
'urlParams' => ['id' => '1'], |
228
|
|
|
'httpCode' => HttpCode::NO_CONTENT, |
229
|
|
|
], |
230
|
|
|
'not found' => [ |
231
|
|
|
'urlParams' => ['id' => '1'], |
232
|
|
|
'httpCode' => HttpCode::NOT_FOUND, |
233
|
|
|
'validationErrors' => [ |
234
|
|
|
'name' => 'The record "1" does not exists.' |
235
|
|
|
], |
236
|
|
|
], |
237
|
|
|
]; |
238
|
|
|
} |
239
|
|
|
/** |
240
|
|
|
* @inheritdoc |
241
|
|
|
*/ |
242
|
|
|
protected function recordJsonType(): array |
243
|
|
|
{ |
244
|
|
|
return [ |
245
|
|
|
'id' => 'integer:>0', |
246
|
|
|
'name' => 'string', |
247
|
|
|
]; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @inheritdoc |
252
|
|
|
*/ |
253
|
|
|
protected function getRoutePattern(): string |
254
|
|
|
{ |
255
|
|
|
return 'w1/workflow'; |
256
|
|
|
} |
257
|
|
|
} |
258
|
|
|
|