diff --git a/composer.json b/composer.json index 02ae3387..9bd4bd0d 100644 --- a/composer.json +++ b/composer.json @@ -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": "*" }, diff --git a/composer.lock b/composer.lock index 1bdec6f2..197df82f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "05ad603d3c0dbf729a64fcd4e9f72e78", + "content-hash": "a82b7377b826040ff9547a8cc13cf241", "packages": [ { "name": "brick/math", @@ -4345,16 +4345,16 @@ }, { "name": "ronasit/laravel-helpers", - "version": "3.0.0-beta", + "version": "3.0.1-beta", "source": { "type": "git", "url": "https://github.com/RonasIT/laravel-helpers.git", - "reference": "b967de51d6a79cc8e18ee707cd8677900fecd304" + "reference": "5bf2992029c1f71269d0fddd036a102822399925" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/RonasIT/laravel-helpers/zipball/b967de51d6a79cc8e18ee707cd8677900fecd304", - "reference": "b967de51d6a79cc8e18ee707cd8677900fecd304", + "url": "https://api.github.com/repos/RonasIT/laravel-helpers/zipball/5bf2992029c1f71269d0fddd036a102822399925", + "reference": "5bf2992029c1f71269d0fddd036a102822399925", "shasum": "" }, "require": { @@ -4421,9 +4421,9 @@ ], "support": { "issues": "https://github.com/RonasIT/laravel-helpers/issues", - "source": "https://github.com/RonasIT/laravel-helpers/tree/3.0.0-beta" + "source": "https://github.com/RonasIT/laravel-helpers/tree/3.0.1-beta" }, - "time": "2024-08-22T13:20:06+00:00" + "time": "2024-11-04T10:52:30+00:00" }, { "name": "sebastian/cli-parser", diff --git a/src/Generators/NovaTestGenerator.php b/src/Generators/NovaTestGenerator.php index 9beb988b..837d7ea8 100644 --- a/src/Generators/NovaTestGenerator.php +++ b/src/Generators/NovaTestGenerator.php @@ -75,7 +75,7 @@ protected function getActions(): array $actionClass = class_basename($action); return [ - 'url' => Str::kebab($actionClass), + 'className' => $actionClass, 'fixture' => Str::snake($actionClass), ]; }, $actions); diff --git a/stubs/nova_test.blade.php b/stubs/nova_test.blade.php index 410f0da8..c27ef395 100644 --- a/stubs/nova_test.blade.php +++ b/stubs/nova_test.blade.php @@ -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 @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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', ], @@ -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); @@ -274,7 +268,7 @@ 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 @@ -282,9 +276,7 @@ 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 @@ -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); @@ -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); diff --git a/tests/NovaTestGeneratorTest.php b/tests/NovaTestGeneratorTest.php index c0ae91c6..ed3e9201 100644 --- a/tests/NovaTestGeneratorTest.php +++ b/tests/NovaTestGeneratorTest.php @@ -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; diff --git a/tests/fixtures/NovaTestGeneratorTest/created_resource_test.php b/tests/fixtures/NovaTestGeneratorTest/created_resource_test.php index 0034597a..73ff5bb6 100644 --- a/tests/fixtures/NovaTestGeneratorTest/created_resource_test.php +++ b/tests/fixtures/NovaTestGeneratorTest/created_resource_test.php @@ -4,7 +4,7 @@ use App\Models\WelcomeBonus; use RonasIT\Support\Tests\ModelTestState; -use RonasIT\Support\Tests\NovaTestTraitTest; +use RonasIT\Support\Traits\NovaTestTrait; class NovaWelcomeBonusTest extends TestCase { @@ -27,7 +27,7 @@ public function testCreate(): void { $data = $this->getJsonFixture('create_welcome_bonus_request.json'); - $response = $this->actingAs(self::$user, 'web')->json('post', '/nova-api/welcome-bonus-resources', $data); + $response = $this->novaActingAs(self::$user)->novaCreateResourceAPICall(WelcomeBonus::class, $data); $response->assertCreated(); @@ -39,7 +39,7 @@ public function testCreate(): void public function testCreateNoAuth(): void { - $response = $this->json('post', '/nova-api/welcome-bonus-resources'); + $response = $this->novaCreateResourceAPICall(WelcomeBonus::class); $response->assertUnauthorized(); @@ -48,7 +48,7 @@ public function testCreateNoAuth(): void public function testCreateValidationError(): void { - $response = $this->actingAs(self::$user, 'web')->json('post', '/nova-api/welcome-bonus-resources'); + $response = $this->novaActingAs(self::$user)->novaCreateResourceAPICall(WelcomeBonus::class); $response->assertUnprocessable(); @@ -62,7 +62,7 @@ public function testUpdate(): void { $data = $this->getJsonFixture('update_welcome_bonus_request.json'); - $response = $this->actingAs(self::$user, 'web')->json('put', '/nova-api/welcome-bonus-resources/1', $data); + $response = $this->novaActingAs(self::$user)->novaUpdateResourceAPICall(WelcomeBonus::class, 1, $data); $response->assertNoContent(); @@ -74,21 +74,21 @@ public function testUpdateNotExists(): void { $data = $this->getJsonFixture('update_welcome_bonus_request.json'); - $response = $this->actingAs(self::$user, 'web')->json('put', '/nova-api/welcome-bonus-resources/0', $data); + $response = $this->novaActingAs(self::$user)->novaUpdateResourceAPICall(WelcomeBonus::class, 0, $data); $response->assertNotFound(); } public function testUpdateNoAuth(): void { - $response = $this->json('put', '/nova-api/welcome-bonus-resources/1'); + $response = $this->novaUpdateResourceAPICall(WelcomeBonus::class, 1); $response->assertUnauthorized(); } public function testUpdateValidationError(): void { - $response = $this->actingAs(self::$user, 'web')->json('put', '/nova-api/welcome-bonus-resources/4'); + $response = $this->novaActingAs(self::$user)->novaUpdateResourceAPICall(WelcomeBonus::class, 4); $response->assertUnprocessable(); @@ -98,7 +98,7 @@ public function testUpdateValidationError(): void public function testGetUpdatableFields(): void { - $response = $this->actingAs(self::$user, 'web')->json('get', '/nova-api/welcome-bonus-resources/1/update-fields'); + $response = $this->novaActingAs(self::$user)->novaGetUpdatableFieldsAPICall(WelcomeBonus::class, 1); $response->assertOk(); @@ -108,9 +108,7 @@ public function testGetUpdatableFields(): void public function testDelete(): void { - $response = $this->actingAs(self::$user, 'web')->json('delete', '/nova-api/welcome-bonus-resources', [ - 'resources' => [1, 2] - ]); + $response = $this->novaActingAs(self::$user)->novaDeleteResourceAPICall(WelcomeBonus::class, [1, 2]); $response->assertOk(); @@ -120,25 +118,21 @@ public function testDelete(): void public function testDeleteNotExists(): void { - $response = $this->actingAs(self::$user, 'web')->json('delete', '/nova-api/welcome-bonus-resources', [ - 'resources' => [0] - ]); + $response = $this->novaActingAs(self::$user)->novaDeleteResourceAPICall(WelcomeBonus::class, [0]); $response->assertNotFound(); } public function testDeleteNoAuth(): void { - $response = $this->json('delete', '/nova-api/welcome-bonus-resources', [ - 'resources' => [1, 2] - ]); + $response = $this->novaDeleteResourceAPICall(WelcomeBonus::class, [1, 2]); $response->assertUnauthorized(); } public function testGet(): void { - $response = $this->actingAs(self::$user, 'web')->json('get', '/nova-api/welcome-bonus-resources/1'); + $response = $this->novaActingAs(self::$user)->novaGetResourceAPICall(WelcomeBonus::class, 1); $response->assertOk(); @@ -148,28 +142,28 @@ public function testGet(): void public function testGetNotExists(): void { - $response = $this->actingAs(self::$user, 'web')->json('get', '/nova-api/welcome-bonus-resources/0'); + $response = $this->novaActingAs(self::$user)->novaGetResourceAPICall(WelcomeBonus::class, 0); $response->assertNotFound(); } public function testGetNoAuth(): void { - $response = $this->json('get', '/nova-api/welcome-bonus-resources/1'); + $response = $this->novaGetResourceAPICall(WelcomeBonus::class, 1); $response->assertUnauthorized(); } public function testSearchUnauthorized(): void { - $response = $this->json('get', '/nova-api/welcome-bonus-resources'); + $response = $this->novaSearchResourceAPICall(WelcomeBonus::class); $response->assertUnauthorized(); } public function testGetFieldsVisibleOnCreate(): void { - $response = $this->actingAs(self::$user, 'web')->json('get', '/nova-api/welcome-bonus-resources/creation-fields'); + $response = $this->novaActingAs(self::$user)->novaGetCreationFieldsAPICall(WelcomeBonus::class); $response->assertOk(); @@ -181,14 +175,14 @@ public function getRunWelcomeBonusActionsData(): array { return [ [ - 'action' => 'publish-post-action', + 'action' => PublishPostAction::class, 'request' => [ 'resources' => '1,2', ], 'state' => 'run_publish_post_action_state.json', ], [ - 'action' => 'un-publish-post-action', + 'action' => UnPublishPostAction::class, 'request' => [ 'resources' => '1,2', ], @@ -200,31 +194,27 @@ public function getRunWelcomeBonusActionsData(): array /** * @dataProvider getRunWelcomeBonusActionsData */ - public function testRunWelcomeBonusActions($action, $request, $welcome_bonusesStateFixture): void + public function testRunWelcomeBonusActions($action, $request, $state): void { - $response = $this->actingAs(self::$user, 'web')->json('post', "/nova-api/welcome-bonus-resources/action?action={$action}", $request); + $response = $this->novaActingAs(self::$user)->novaRunActionAPICall(WelcomeBonus::class, $action, $request); $response->assertOk(); $this->assertEmpty($response->getContent()); // TODO: Need to remove after first successful start - self::$welcomeBonusState->assertChangesEqualsFixture($welcome_bonusesStateFixture, true); + self::$welcomeBonusState->assertChangesEqualsFixture($state, true); } public function getWelcomeBonusActionsData(): array { return [ [ - 'request' => [ - 'resources' => '1,2', - ], + 'resources' => [1, 2], 'response_fixture' => 'get_welcome_bonus_actions_publish_post_action.json', ], [ - 'request' => [ - 'resources' => '1,2', - ], + 'resources' => [1, 2], 'response_fixture' => 'get_welcome_bonus_actions_un_publish_post_action.json', ], ]; @@ -233,9 +223,9 @@ public function getWelcomeBonusActionsData(): array /** * @dataProvider getWelcomeBonusActionsData */ - public function testGetWelcomeBonusActions(array $request, string $responseFixture): void + public function testGetWelcomeBonusActions(array $resources, string $responseFixture): void { - $response = $this->actingAs(self::$user, 'web')->json('get', '/nova-api/welcome-bonus-resources/actions', $request); + $response = $this->novaActingAs(self::$user)->novaGetActionsAPICall(WelcomeBonus::class, $resources); $response->assertOk(); @@ -266,7 +256,7 @@ public function getWelcomeBonusFiltersData(): array */ public function testFilterWelcomeBonus(array $request, string $responseFixture): void { - $response = $this->actingAs(self::$user, 'web')->json('get', '/nova-api/welcome-bonus-resources', $request); + $response = $this->novaActingAs(self::$user)->novaSearchResourceAPICall(WelcomeBonus::class, $request); $response->assertOk();