1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace App\Tests\Acceptance; |
6
|
|
|
|
7
|
|
|
use App\Tests\AcceptanceTester; |
8
|
|
|
use Codeception\Util\HttpCode; |
9
|
|
|
|
10
|
|
|
final class BlogCest |
11
|
|
|
{ |
12
|
|
|
public function create(AcceptanceTester $I): void |
13
|
|
|
{ |
14
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
15
|
|
|
$I->haveHttpHeader( |
16
|
|
|
'X-Api-Key', |
17
|
|
|
'lev1ZsWCzqrMlXRI2sT8h4ApYpSgBMl1xf6D4bCRtiKtDqw6JN36yLznargilQ_rEJz9zTfcUxm53PLODCToF9gGin38Rd4NkhQPOVeH5VvZvBaQlUg64E6icNCubiAv' |
18
|
|
|
); |
19
|
|
|
|
20
|
|
|
$I->sendPOST( |
21
|
|
|
'/blog/', |
22
|
|
|
[ |
23
|
|
|
'title' => 'test title', |
24
|
|
|
'text' => 'test text', |
25
|
|
|
'status' => 0, |
26
|
|
|
] |
27
|
|
|
); |
28
|
|
|
$I->seeResponseCodeIs(HttpCode::OK); |
29
|
|
|
$I->seeResponseIsJson(); |
30
|
|
|
$I->seeResponseContainsJson( |
31
|
|
|
[ |
32
|
|
|
'status' => 'success', |
33
|
|
|
'error_message' => '', |
34
|
|
|
'error_code' => null, |
35
|
|
|
'data' => null, |
36
|
|
|
] |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
$I->seeInDatabase( |
40
|
|
|
'post', |
41
|
|
|
[ |
42
|
|
|
'title' => 'test title', |
43
|
|
|
'content' => 'test text', |
44
|
|
|
'status' => 0, |
45
|
|
|
] |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function createBadParams(AcceptanceTester $I): void |
50
|
|
|
{ |
51
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
52
|
|
|
$I->haveHttpHeader( |
53
|
|
|
'X-Api-Key', |
54
|
|
|
'lev1ZsWCzqrMlXRI2sT8h4ApYpSgBMl1xf6D4bCRtiKtDqw6JN36yLznargilQ_rEJz9zTfcUxm53PLODCToF9gGin38Rd4NkhQPOVeH5VvZvBaQlUg64E6icNCubiAv' |
55
|
|
|
); |
56
|
|
|
|
57
|
|
|
$I->sendPOST( |
58
|
|
|
'/blog/', |
59
|
|
|
[ |
60
|
|
|
'title' => 'test title', |
61
|
|
|
'status' => 100, |
62
|
|
|
] |
63
|
|
|
); |
64
|
|
|
$I->seeResponseCodeIs(HttpCode::BAD_REQUEST); |
65
|
|
|
$I->seeResponseIsJson(); |
66
|
|
|
$I->seeResponseContainsJson( |
67
|
|
|
[ |
68
|
|
|
'status' => 'failed', |
69
|
|
|
'error_message' => 'Value cannot be blank.', |
70
|
|
|
'error_code' => 400, |
71
|
|
|
'data' => null, |
72
|
|
|
] |
73
|
|
|
); |
74
|
|
|
|
75
|
|
|
$I->dontSeeInDatabase( |
76
|
|
|
'post', |
77
|
|
|
[ |
78
|
|
|
'title' => 'test title', |
79
|
|
|
'status' => 100, |
80
|
|
|
] |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function createBadAuth(AcceptanceTester $I): void |
85
|
|
|
{ |
86
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
87
|
|
|
$I->sendPOST( |
88
|
|
|
'/blog/', |
89
|
|
|
[ |
90
|
|
|
'title' => 'test title', |
91
|
|
|
'text' => 'test text', |
92
|
|
|
'status' => 0, |
93
|
|
|
] |
94
|
|
|
); |
95
|
|
|
$I->seeResponseCodeIs(HttpCode::UNAUTHORIZED); |
96
|
|
|
$I->seeResponseIsJson(); |
97
|
|
|
$I->seeResponseContainsJson( |
98
|
|
|
[ |
99
|
|
|
'status' => 'failed', |
100
|
|
|
'error_message' => 'Unauthorised request', |
101
|
|
|
'error_code' => HttpCode::UNAUTHORIZED, |
102
|
|
|
'data' => null, |
103
|
|
|
] |
104
|
|
|
); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function update(AcceptanceTester $I): void |
108
|
|
|
{ |
109
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
110
|
|
|
$I->haveHttpHeader( |
111
|
|
|
'X-Api-Key', |
112
|
|
|
'lev1ZsWCzqrMlXRI2sT8h4ApYpSgBMl1xf6D4bCRtiKtDqw6JN36yLznargilQ_rEJz9zTfcUxm53PLODCToF9gGin38Rd4NkhQPOVeH5VvZvBaQlUg64E6icNCubiAv' |
113
|
|
|
); |
114
|
|
|
|
115
|
|
|
$I->sendPUT( |
116
|
|
|
'/blog/1', |
117
|
|
|
[ |
118
|
|
|
'title' => 'test title', |
119
|
|
|
'text' => 'test text', |
120
|
|
|
'status' => 0, |
121
|
|
|
] |
122
|
|
|
); |
123
|
|
|
$I->seeResponseCodeIs(HttpCode::OK); |
124
|
|
|
$I->seeResponseIsJson(); |
125
|
|
|
$I->seeResponseContainsJson( |
126
|
|
|
[ |
127
|
|
|
'status' => 'success', |
128
|
|
|
'error_message' => '', |
129
|
|
|
'error_code' => null, |
130
|
|
|
'data' => null, |
131
|
|
|
] |
132
|
|
|
); |
133
|
|
|
|
134
|
|
|
$I->seeInDatabase( |
135
|
|
|
'post', |
136
|
|
|
[ |
137
|
|
|
'id' => 1, |
138
|
|
|
'title' => 'test title', |
139
|
|
|
'content' => 'test text', |
140
|
|
|
'status' => 0, |
141
|
|
|
] |
142
|
|
|
); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
public function updateBadAuth(AcceptanceTester $I): void |
146
|
|
|
{ |
147
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
148
|
|
|
$I->sendPUT( |
149
|
|
|
'/blog/1', |
150
|
|
|
[ |
151
|
|
|
'title' => 'test title', |
152
|
|
|
'text' => 'test text', |
153
|
|
|
'status' => 0, |
154
|
|
|
] |
155
|
|
|
); |
156
|
|
|
$I->seeResponseCodeIs(HttpCode::UNAUTHORIZED); |
157
|
|
|
$I->seeResponseIsJson(); |
158
|
|
|
$I->seeResponseContainsJson( |
159
|
|
|
[ |
160
|
|
|
'status' => 'failed', |
161
|
|
|
'error_message' => 'Unauthorised request', |
162
|
|
|
'error_code' => HttpCode::UNAUTHORIZED, |
163
|
|
|
'data' => null, |
164
|
|
|
] |
165
|
|
|
); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
public function index(AcceptanceTester $I): void |
169
|
|
|
{ |
170
|
|
|
$I->sendGET( |
171
|
|
|
'/blog/', |
172
|
|
|
[ |
173
|
|
|
'page' => 2, |
174
|
|
|
] |
175
|
|
|
); |
176
|
|
|
$I->seeResponseCodeIs(HttpCode::OK); |
177
|
|
|
$I->seeResponseIsJson(); |
178
|
|
|
$I->seeResponseContainsJson( |
179
|
|
|
[ |
180
|
|
|
'status' => 'success', |
181
|
|
|
'error_message' => '', |
182
|
|
|
'error_code' => null, |
183
|
|
|
'data' => [ |
184
|
|
|
'paginator' => [ |
185
|
|
|
'pageSize' => 10, |
186
|
|
|
'currentPage' => 2, |
187
|
|
|
'totalPages' => 2, |
188
|
|
|
], |
189
|
|
|
'posts' => [ |
190
|
|
|
[ |
191
|
|
|
'id' => 11, |
192
|
|
|
'title' => 'Eveniet est nam sapiente odit architecto et.', |
193
|
|
|
], |
194
|
|
|
], |
195
|
|
|
], |
196
|
|
|
] |
197
|
|
|
); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
public function view(AcceptanceTester $I): void |
201
|
|
|
{ |
202
|
|
|
$I->sendGET('/blog/11'); |
203
|
|
|
$I->seeResponseCodeIs(HttpCode::OK); |
204
|
|
|
$I->seeResponseIsJson(); |
205
|
|
|
$I->seeResponseContainsJson( |
206
|
|
|
[ |
207
|
|
|
'status' => 'success', |
208
|
|
|
'error_message' => '', |
209
|
|
|
'error_code' => null, |
210
|
|
|
'data' => [ |
211
|
|
|
'post' => [ |
212
|
|
|
'id' => 11, |
213
|
|
|
'title' => 'Eveniet est nam sapiente odit architecto et.', |
214
|
|
|
], |
215
|
|
|
], |
216
|
|
|
] |
217
|
|
|
); |
218
|
|
|
} |
219
|
|
|
} |
220
|
|
|
|