Skip to content

Commit

Permalink
Merge pull request #96 from RonasIT/update-nova-test-generator-template
Browse files Browse the repository at this point in the history
feat: update nova test generator template
  • Loading branch information
DenTray authored Nov 11, 2024
2 parents 1ff7cd3 + 554aeba commit 2e111c7
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 80 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"require": {
"php": "^8.3",
"laravel/framework": "^11.21",
"ronasit/laravel-helpers": "^3.0.0-beta",
"ronasit/laravel-helpers": "^3.0.1-beta",
"laravel/legacy-factories": ">=1.3.0",
"ext-json": "*"
},
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Generators/NovaTestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected function getActions(): array
$actionClass = class_basename($action);

return [
'url' => Str::kebab($actionClass),
'className' => $actionClass,
'fixture' => Str::snake($actionClass),
];
}, $actions);
Expand Down
58 changes: 25 additions & 33 deletions stubs/nova_test.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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

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

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

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

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

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

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

$response = $this->actingAs(self::$user, 'web')->json('put', '/nova-api/{{$url_path}}/1', $data);
$response = $this->novaActingAs(self::$user)->novaUpdateResourceAPICall({{$entity}}::class, 1, $data);

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

$response = $this->actingAs(self::$user, 'web')->json('put', '/nova-api/{{$url_path}}/0', $data);
$response = $this->novaActingAs(self::$user)->novaUpdateResourceAPICall({{$entity}}::class, 0, $data);

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

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

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

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

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

public function testGetUpdatableFields(): void
{
$response = $this->actingAs(self::$user, 'web')->json('get', '/nova-api/{{$url_path}}/1/update-fields');
$response = $this->novaActingAs(self::$user)->novaGetUpdatableFieldsAPICall({{$entity}}::class, 1);

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

public function testDelete(): void
{
$response = $this->actingAs(self::$user, 'web')->json('delete', '/nova-api/{{$url_path}}', [
'resources' => [1, 2]
]);
$response = $this->novaActingAs(self::$user)->novaDeleteResourceAPICall({{$entity}}::class, [1, 2]);

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

public function testDeleteNotExists(): void
{
$response = $this->actingAs(self::$user, 'web')->json('delete', '/nova-api/{{$url_path}}', [
'resources' => [0]
]);
$response = $this->novaActingAs(self::$user)->novaDeleteResourceAPICall({{$entity}}::class, [0]);

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

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

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

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

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

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

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

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

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

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

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

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

@if($shouldUseStatus)
$response->assertStatus(Response::HTTP_OK);
Expand All @@ -248,7 +242,7 @@ public function getRun{{$entity}}ActionsData(): array
return [
@foreach($actions as $action)
[
'action' => '{{$action['url']}}',
'action' => {{$action['className']}}::class,
'request' => [
'resources' => '1,2',
],
Expand All @@ -261,9 +255,9 @@ public function getRun{{$entity}}ActionsData(): array
/**
* @dataProvider getRun{{$entity}}ActionsData
*/
public function testRun{{$entity}}Actions($action, $request, ${{$lower_entities}}StateFixture): void
public function testRun{{$entity}}Actions($action, $request, $state): void
{
$response = $this->actingAs(self::$user, 'web')->json('post', "/nova-api/{{$url_path}}/action?action={$action}", $request);
$response = $this->novaActingAs(self::$user)->novaRunActionAPICall({{$entity}}::class, $action, $request);

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

// TODO: Need to remove after first successful start
self::${{$dromedary_entity}}State->assertChangesEqualsFixture(${{$lower_entities}}StateFixture, true);
self::${{$dromedary_entity}}State->assertChangesEqualsFixture($state, true);
}

public function get{{$entity}}ActionsData(): array
{
return [
@foreach($actions as $action)
[
'request' => [
'resources' => '1,2',
],
'resources' => [1, 2],
'response_fixture' => 'get_{{$snake_entity}}_actions_{{$action['fixture']}}.json',
],
@endforeach
Expand All @@ -294,9 +286,9 @@ public function get{{$entity}}ActionsData(): array
/**
* @dataProvider get{{$entity}}ActionsData
*/
public function testGet{{$entity}}Actions(array $request, string $responseFixture): void
public function testGet{{$entity}}Actions(array $resources, string $responseFixture): void
{
$response = $this->actingAs(self::$user, 'web')->json('get', '/nova-api/{{$url_path}}/actions', $request);
$response = $this->novaActingAs(self::$user)->novaGetActionsAPICall({{$entity}}::class, $resources);

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

@if($shouldUseStatus)
$response->assertStatus(Response::HTTP_OK);
Expand Down
1 change: 0 additions & 1 deletion tests/NovaTestGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace RonasIT\Support\Tests;

use org\bovigo\vfs\vfsStream;
use RonasIT\Support\Exceptions\ClassAlreadyExistsException;
use RonasIT\Support\Exceptions\ClassNotExistsException;
use RonasIT\Support\Generators\NovaTestGenerator;
Expand Down
Loading

0 comments on commit 2e111c7

Please sign in to comment.