Skip to content

Commit 2e111c7

Browse files
authored
Merge pull request #96 from RonasIT/update-nova-test-generator-template
feat: update nova test generator template
2 parents 1ff7cd3 + 554aeba commit 2e111c7

File tree

6 files changed

+61
-80
lines changed

6 files changed

+61
-80
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"require": {
1313
"php": "^8.3",
1414
"laravel/framework": "^11.21",
15-
"ronasit/laravel-helpers": "^3.0.0-beta",
15+
"ronasit/laravel-helpers": "^3.0.1-beta",
1616
"laravel/legacy-factories": ">=1.3.0",
1717
"ext-json": "*"
1818
},

composer.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Generators/NovaTestGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ protected function getActions(): array
7575
$actionClass = class_basename($action);
7676

7777
return [
78-
'url' => Str::kebab($actionClass),
78+
'className' => $actionClass,
7979
'fixture' => Str::snake($actionClass),
8080
];
8181
}, $actions);

stubs/nova_test.blade.php

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use App\Models\{{$entity}};
55
use RonasIT\Support\Tests\ModelTestState;
6-
use RonasIT\Support\Tests\NovaTestTraitTest;
6+
use RonasIT\Support\Traits\NovaTestTrait;
77
@if($shouldUseStatus)
88
use Symfony\Component\HttpFoundation\Response;
99
@endif
@@ -29,7 +29,7 @@ public function testCreate(): void
2929
{
3030
$data = $this->getJsonFixture('create_{{$snake_entity}}_request.json');
3131

32-
$response = $this->actingAs(self::$user, 'web')->json('post', '/nova-api/{{$url_path}}', $data);
32+
$response = $this->novaActingAs(self::$user)->novaCreateResourceAPICall({{$entity}}::class, $data);
3333

3434
@if($shouldUseStatus)
3535
$response->assertStatus(Response::HTTP_CREATED);
@@ -45,7 +45,7 @@ public function testCreate(): void
4545

4646
public function testCreateNoAuth(): void
4747
{
48-
$response = $this->json('post', '/nova-api/{{$url_path}}');
48+
$response = $this->novaCreateResourceAPICall({{$entity}}::class);
4949

5050
@if($shouldUseStatus)
5151
$response->assertStatus(Response::HTTP_UNAUTHORIZED);
@@ -58,7 +58,7 @@ public function testCreateNoAuth(): void
5858

5959
public function testCreateValidationError(): void
6060
{
61-
$response = $this->actingAs(self::$user, 'web')->json('post', '/nova-api/{{$url_path}}');
61+
$response = $this->novaActingAs(self::$user)->novaCreateResourceAPICall({{$entity}}::class);
6262

6363
@if($shouldUseStatus)
6464
$response->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY);
@@ -76,7 +76,7 @@ public function testUpdate(): void
7676
{
7777
$data = $this->getJsonFixture('update_{{$snake_entity}}_request.json');
7878

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);
8080

8181
@if($shouldUseStatus)
8282
$response->assertStatus(Response::HTTP_NO_CONTENT);
@@ -92,7 +92,7 @@ public function testUpdateNotExists(): void
9292
{
9393
$data = $this->getJsonFixture('update_{{$snake_entity}}_request.json');
9494

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);
9696

9797
@if($shouldUseStatus)
9898
$response->assertStatus(Response::HTTP_NOT_FOUND);
@@ -103,7 +103,7 @@ public function testUpdateNotExists(): void
103103

104104
public function testUpdateNoAuth(): void
105105
{
106-
$response = $this->json('put', '/nova-api/{{$url_path}}/1');
106+
$response = $this->novaUpdateResourceAPICall({{$entity}}::class, 1);
107107

108108
@if($shouldUseStatus)
109109
$response->assertStatus(Response::HTTP_UNAUTHORIZED);
@@ -114,7 +114,7 @@ public function testUpdateNoAuth(): void
114114

115115
public function testUpdateValidationError(): void
116116
{
117-
$response = $this->actingAs(self::$user, 'web')->json('put', '/nova-api/{{$url_path}}/4');
117+
$response = $this->novaActingAs(self::$user)->novaUpdateResourceAPICall({{$entity}}::class, 4);
118118

119119
@if($shouldUseStatus)
120120
$response->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY);
@@ -128,7 +128,7 @@ public function testUpdateValidationError(): void
128128

129129
public function testGetUpdatableFields(): void
130130
{
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);
132132

133133
@if($shouldUseStatus)
134134
$response->assertStatus(Response::HTTP_OK);
@@ -142,9 +142,7 @@ public function testGetUpdatableFields(): void
142142

143143
public function testDelete(): void
144144
{
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]);
148146

149147
@if($shouldUseStatus)
150148
$response->assertStatus(Response::HTTP_OK);
@@ -158,9 +156,7 @@ public function testDelete(): void
158156

159157
public function testDeleteNotExists(): void
160158
{
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]);
164160

165161
@if($shouldUseStatus)
166162
$response->assertStatus(Response::HTTP_NOT_FOUND);
@@ -171,9 +167,7 @@ public function testDeleteNotExists(): void
171167

172168
public function testDeleteNoAuth(): void
173169
{
174-
$response = $this->json('delete', '/nova-api/{{$url_path}}', [
175-
'resources' => [1, 2]
176-
]);
170+
$response = $this->novaDeleteResourceAPICall({{$entity}}::class, [1, 2]);
177171

178172
@if($shouldUseStatus)
179173
$response->assertStatus(Response::HTTP_UNAUTHORIZED);
@@ -184,7 +178,7 @@ public function testDeleteNoAuth(): void
184178

185179
public function testGet(): void
186180
{
187-
$response = $this->actingAs(self::$user, 'web')->json('get', '/nova-api/{{$url_path}}/1');
181+
$response = $this->novaActingAs(self::$user)->novaGetResourceAPICall({{$entity}}::class, 1);
188182

189183
@if($shouldUseStatus)
190184
$response->assertStatus(Response::HTTP_OK);
@@ -198,7 +192,7 @@ public function testGet(): void
198192

199193
public function testGetNotExists(): void
200194
{
201-
$response = $this->actingAs(self::$user, 'web')->json('get', '/nova-api/{{$url_path}}/0');
195+
$response = $this->novaActingAs(self::$user)->novaGetResourceAPICall({{$entity}}::class, 0);
202196

203197
@if($shouldUseStatus)
204198
$response->assertStatus(Response::HTTP_NOT_FOUND);
@@ -209,7 +203,7 @@ public function testGetNotExists(): void
209203

210204
public function testGetNoAuth(): void
211205
{
212-
$response = $this->json('get', '/nova-api/{{$url_path}}/1');
206+
$response = $this->novaGetResourceAPICall({{$entity}}::class, 1);
213207

214208
@if($shouldUseStatus)
215209
$response->assertStatus(Response::HTTP_UNAUTHORIZED);
@@ -220,7 +214,7 @@ public function testGetNoAuth(): void
220214

221215
public function testSearchUnauthorized(): void
222216
{
223-
$response = $this->json('get', '/nova-api/{{$url_path}}');
217+
$response = $this->novaSearchResourceAPICall({{$entity}}::class);
224218

225219
@if($shouldUseStatus)
226220
$response->assertStatus(Response::HTTP_UNAUTHORIZED);
@@ -231,7 +225,7 @@ public function testSearchUnauthorized(): void
231225

232226
public function testGetFieldsVisibleOnCreate(): void
233227
{
234-
$response = $this->actingAs(self::$user, 'web')->json('get', '/nova-api/{{$url_path}}/creation-fields');
228+
$response = $this->novaActingAs(self::$user)->novaGetCreationFieldsAPICall({{$entity}}::class);
235229

236230
@if($shouldUseStatus)
237231
$response->assertStatus(Response::HTTP_OK);
@@ -248,7 +242,7 @@ public function getRun{{$entity}}ActionsData(): array
248242
return [
249243
@foreach($actions as $action)
250244
[
251-
'action' => '{{$action['url']}}',
245+
'action' => {{$action['className']}}::class,
252246
'request' => [
253247
'resources' => '1,2',
254248
],
@@ -261,9 +255,9 @@ public function getRun{{$entity}}ActionsData(): array
261255
/**
262256
* @dataProvider getRun{{$entity}}ActionsData
263257
*/
264-
public function testRun{{$entity}}Actions($action, $request, ${{$lower_entities}}StateFixture): void
258+
public function testRun{{$entity}}Actions($action, $request, $state): void
265259
{
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);
267261

268262
@if($shouldUseStatus)
269263
$response->assertStatus(Response::HTTP_OK);
@@ -274,17 +268,15 @@ public function testRun{{$entity}}Actions($action, $request, ${{$lower_entities}
274268
$this->assertEmpty($response->getContent());
275269

276270
// 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);
278272
}
279273

280274
public function get{{$entity}}ActionsData(): array
281275
{
282276
return [
283277
@foreach($actions as $action)
284278
[
285-
'request' => [
286-
'resources' => '1,2',
287-
],
279+
'resources' => [1, 2],
288280
'response_fixture' => 'get_{{$snake_entity}}_actions_{{$action['fixture']}}.json',
289281
],
290282
@endforeach
@@ -294,9 +286,9 @@ public function get{{$entity}}ActionsData(): array
294286
/**
295287
* @dataProvider get{{$entity}}ActionsData
296288
*/
297-
public function testGet{{$entity}}Actions(array $request, string $responseFixture): void
289+
public function testGet{{$entity}}Actions(array $resources, string $responseFixture): void
298290
{
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);
300292

301293
@if($shouldUseStatus)
302294
$response->assertStatus(Response::HTTP_OK);
@@ -327,7 +319,7 @@ public function get{{$entity}}FiltersData(): array
327319
*/
328320
public function testFilter{{$entity}}(array $request, string $responseFixture): void
329321
{
330-
$response = $this->actingAs(self::$user, 'web')->json('get', '/nova-api/{{$url_path}}', $request);
322+
$response = $this->novaActingAs(self::$user)->novaSearchResourceAPICall({{$entity}}::class, $request);
331323

332324
@if($shouldUseStatus)
333325
$response->assertStatus(Response::HTTP_OK);

tests/NovaTestGeneratorTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace RonasIT\Support\Tests;
44

5-
use org\bovigo\vfs\vfsStream;
65
use RonasIT\Support\Exceptions\ClassAlreadyExistsException;
76
use RonasIT\Support\Exceptions\ClassNotExistsException;
87
use RonasIT\Support\Generators\NovaTestGenerator;

0 commit comments

Comments
 (0)