3
3
4
4
use App\Models\{{ $entity } } ;
5
5
use RonasIT\Support\Tests\ModelTestState;
6
- use RonasIT\Support\Tests\NovaTestTraitTest ;
6
+ use RonasIT\Support\Traits\NovaTestTrait ;
7
7
@if ($shouldUseStatus )
8
8
use Symfony\Component\HttpFoundation\Response;
9
9
@endif
@@ -29,7 +29,7 @@ public function testCreate(): void
29
29
{
30
30
$data = $this->getJsonFixture('create_{{ $snake_entity } } _request.json');
31
31
32
- $response = $this->actingAs (self::$user, 'web' )->json('post', '/nova-api/ {{ $url_path } } ' , $data);
32
+ $response = $this->novaActingAs (self::$user)->novaCreateResourceAPICall( {{ $entity } } ::class , $data);
33
33
34
34
@if ($shouldUseStatus )
35
35
$response->assertStatus(Response::HTTP_CREATED);
@@ -45,7 +45,7 @@ public function testCreate(): void
45
45
46
46
public function testCreateNoAuth(): void
47
47
{
48
- $response = $this->json('post', '/nova-api/ {{ $url_path } } ' );
48
+ $response = $this->novaCreateResourceAPICall( {{ $entity } } ::class );
49
49
50
50
@if ($shouldUseStatus )
51
51
$response->assertStatus(Response::HTTP_UNAUTHORIZED);
@@ -58,7 +58,7 @@ public function testCreateNoAuth(): void
58
58
59
59
public function testCreateValidationError(): void
60
60
{
61
- $response = $this->actingAs (self::$user, 'web' )->json('post', '/nova-api/ {{ $url_path } } ' );
61
+ $response = $this->novaActingAs (self::$user)->novaCreateResourceAPICall( {{ $entity } } ::class );
62
62
63
63
@if ($shouldUseStatus )
64
64
$response->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY);
@@ -76,7 +76,7 @@ public function testUpdate(): void
76
76
{
77
77
$data = $this->getJsonFixture('update_{{ $snake_entity } } _request.json');
78
78
79
- $response = $this->actingAs (self::$user, 'web' )->json('put', '/nova-api/ {{ $url_path } } /1' , $data);
79
+ $response = $this->novaActingAs (self::$user)->novaUpdateResourceAPICall( {{ $entity } } ::class, 1 , $data);
80
80
81
81
@if ($shouldUseStatus )
82
82
$response->assertStatus(Response::HTTP_NO_CONTENT);
@@ -92,7 +92,7 @@ public function testUpdateNotExists(): void
92
92
{
93
93
$data = $this->getJsonFixture('update_{{ $snake_entity } } _request.json');
94
94
95
- $response = $this->actingAs (self::$user, 'web' )->json('put', '/nova-api/ {{ $url_path } } /0' , $data);
95
+ $response = $this->novaActingAs (self::$user)->novaUpdateResourceAPICall( {{ $entity } } ::class, 0 , $data);
96
96
97
97
@if ($shouldUseStatus )
98
98
$response->assertStatus(Response::HTTP_NOT_FOUND);
@@ -103,7 +103,7 @@ public function testUpdateNotExists(): void
103
103
104
104
public function testUpdateNoAuth(): void
105
105
{
106
- $response = $this->json('put', '/nova-api/ {{ $url_path } } /1' );
106
+ $response = $this->novaUpdateResourceAPICall( {{ $entity } } ::class, 1 );
107
107
108
108
@if ($shouldUseStatus )
109
109
$response->assertStatus(Response::HTTP_UNAUTHORIZED);
@@ -114,7 +114,7 @@ public function testUpdateNoAuth(): void
114
114
115
115
public function testUpdateValidationError(): void
116
116
{
117
- $response = $this->actingAs (self::$user, 'web' )->json('put', '/nova-api/ {{ $url_path } } /4' );
117
+ $response = $this->novaActingAs (self::$user)->novaUpdateResourceAPICall( {{ $entity } } ::class, 4 );
118
118
119
119
@if ($shouldUseStatus )
120
120
$response->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY);
@@ -128,7 +128,7 @@ public function testUpdateValidationError(): void
128
128
129
129
public function testGetUpdatableFields(): void
130
130
{
131
- $response = $this->actingAs (self::$user, 'web' )->json('get', '/nova-api/ {{ $url_path } } /1/update-fields' );
131
+ $response = $this->novaActingAs (self::$user)->novaGetUpdatableFieldsAPICall( {{ $entity } } ::class, 1 );
132
132
133
133
@if ($shouldUseStatus )
134
134
$response->assertStatus(Response::HTTP_OK);
@@ -142,9 +142,7 @@ public function testGetUpdatableFields(): void
142
142
143
143
public function testDelete(): void
144
144
{
145
- $response = $this->actingAs(self::$user, 'web')->json('delete', '/nova-api/{{ $url_path } } ', [
146
- 'resources' => [1, 2]
147
- ]);
145
+ $response = $this->novaActingAs(self::$user)->novaDeleteResourceAPICall({{ $entity } } ::class, [1, 2]);
148
146
149
147
@if ($shouldUseStatus )
150
148
$response->assertStatus(Response::HTTP_OK);
@@ -158,9 +156,7 @@ public function testDelete(): void
158
156
159
157
public function testDeleteNotExists(): void
160
158
{
161
- $response = $this->actingAs(self::$user, 'web')->json('delete', '/nova-api/{{ $url_path } } ', [
162
- 'resources' => [0]
163
- ]);
159
+ $response = $this->novaActingAs(self::$user)->novaDeleteResourceAPICall({{ $entity } } ::class, [0]);
164
160
165
161
@if ($shouldUseStatus )
166
162
$response->assertStatus(Response::HTTP_NOT_FOUND);
@@ -171,9 +167,7 @@ public function testDeleteNotExists(): void
171
167
172
168
public function testDeleteNoAuth(): void
173
169
{
174
- $response = $this->json('delete', '/nova-api/{{ $url_path } } ', [
175
- 'resources' => [1, 2]
176
- ]);
170
+ $response = $this->novaDeleteResourceAPICall({{ $entity } } ::class, [1, 2]);
177
171
178
172
@if ($shouldUseStatus )
179
173
$response->assertStatus(Response::HTTP_UNAUTHORIZED);
@@ -184,7 +178,7 @@ public function testDeleteNoAuth(): void
184
178
185
179
public function testGet(): void
186
180
{
187
- $response = $this->actingAs (self::$user, 'web' )->json('get', '/nova-api/ {{ $url_path } } /1' );
181
+ $response = $this->novaActingAs (self::$user)->novaGetResourceAPICall( {{ $entity } } ::class, 1 );
188
182
189
183
@if ($shouldUseStatus )
190
184
$response->assertStatus(Response::HTTP_OK);
@@ -198,7 +192,7 @@ public function testGet(): void
198
192
199
193
public function testGetNotExists(): void
200
194
{
201
- $response = $this->actingAs (self::$user, 'web' )->json('get', '/nova-api/ {{ $url_path } } /0' );
195
+ $response = $this->novaActingAs (self::$user)->novaGetResourceAPICall( {{ $entity } } ::class, 0 );
202
196
203
197
@if ($shouldUseStatus )
204
198
$response->assertStatus(Response::HTTP_NOT_FOUND);
@@ -209,7 +203,7 @@ public function testGetNotExists(): void
209
203
210
204
public function testGetNoAuth(): void
211
205
{
212
- $response = $this->json('get', '/nova-api/ {{ $url_path } } /1' );
206
+ $response = $this->novaGetResourceAPICall( {{ $entity } } ::class, 1 );
213
207
214
208
@if ($shouldUseStatus )
215
209
$response->assertStatus(Response::HTTP_UNAUTHORIZED);
@@ -220,7 +214,7 @@ public function testGetNoAuth(): void
220
214
221
215
public function testSearchUnauthorized(): void
222
216
{
223
- $response = $this->json('get', '/nova-api/ {{ $url_path } } ' );
217
+ $response = $this->novaSearchResourceAPICall( {{ $entity } } ::class );
224
218
225
219
@if ($shouldUseStatus )
226
220
$response->assertStatus(Response::HTTP_UNAUTHORIZED);
@@ -231,7 +225,7 @@ public function testSearchUnauthorized(): void
231
225
232
226
public function testGetFieldsVisibleOnCreate(): void
233
227
{
234
- $response = $this->actingAs (self::$user, 'web' )->json('get', '/nova-api/ {{ $url_path } } /creation-fields' );
228
+ $response = $this->novaActingAs (self::$user)->novaGetCreationFieldsAPICall( {{ $entity } } ::class );
235
229
236
230
@if ($shouldUseStatus )
237
231
$response->assertStatus(Response::HTTP_OK);
@@ -248,7 +242,7 @@ public function getRun{{$entity}}ActionsData(): array
248
242
return [
249
243
@foreach ($actions as $action )
250
244
[
251
- 'action' => ' {{ $action [' url ' ]} }' ,
245
+ 'action' => {{ $action [' className ' ]} }::class ,
252
246
'request' => [
253
247
'resources' => '1,2',
254
248
],
@@ -261,9 +255,9 @@ public function getRun{{$entity}}ActionsData(): array
261
255
/**
262
256
* @dataProvider getRun{{ $entity } } ActionsData
263
257
*/
264
- public function testRun{{ $entity } } Actions($action, $request, ${{ $lower_entities } } StateFixture ): void
258
+ public function testRun{{ $entity } } Actions($action, $request, $state ): void
265
259
{
266
- $response = $this->actingAs (self::$user, 'web' )->json('post', "/nova-api/ {{ $url_path } } /action?action={ $action}" , $request);
260
+ $response = $this->novaActingAs (self::$user)->novaRunActionAPICall( {{ $entity } } ::class, $action, $request);
267
261
268
262
@if ($shouldUseStatus )
269
263
$response->assertStatus(Response::HTTP_OK);
@@ -274,17 +268,15 @@ public function testRun{{$entity}}Actions($action, $request, ${{$lower_entities}
274
268
$this->assertEmpty($response->getContent());
275
269
276
270
// TODO: Need to remove after first successful start
277
- self::${{ $dromedary_entity } } State->assertChangesEqualsFixture(${{ $lower_entities } } StateFixture , true);
271
+ self::${{ $dromedary_entity } } State->assertChangesEqualsFixture($state , true);
278
272
}
279
273
280
274
public function get{{ $entity } } ActionsData(): array
281
275
{
282
276
return [
283
277
@foreach ($actions as $action )
284
278
[
285
- 'request' => [
286
- 'resources' => '1,2',
287
- ],
279
+ 'resources' => [1, 2],
288
280
'response_fixture' => 'get_{{ $snake_entity } } _actions_{{ $action [' fixture' ]} } .json',
289
281
],
290
282
@endforeach
@@ -294,9 +286,9 @@ public function get{{$entity}}ActionsData(): array
294
286
/**
295
287
* @dataProvider get{{ $entity } } ActionsData
296
288
*/
297
- public function testGet{{ $entity } } Actions(array $request , string $responseFixture): void
289
+ public function testGet{{ $entity } } Actions(array $resources , string $responseFixture): void
298
290
{
299
- $response = $this->actingAs (self::$user, 'web' )->json('get', '/nova-api/ {{ $url_path } } /actions' , $request );
291
+ $response = $this->novaActingAs (self::$user)->novaGetActionsAPICall( {{ $entity } } ::class , $resources );
300
292
301
293
@if ($shouldUseStatus )
302
294
$response->assertStatus(Response::HTTP_OK);
@@ -327,7 +319,7 @@ public function get{{$entity}}FiltersData(): array
327
319
*/
328
320
public function testFilter{{ $entity } } (array $request, string $responseFixture): void
329
321
{
330
- $response = $this->actingAs (self::$user, 'web' )->json('get', '/nova-api/ {{ $url_path } } ' , $request);
322
+ $response = $this->novaActingAs (self::$user)->novaSearchResourceAPICall( {{ $entity } } ::class , $request);
331
323
332
324
@if ($shouldUseStatus )
333
325
$response->assertStatus(Response::HTTP_OK);
0 commit comments