diff --git a/app/Containers/AppSection/User/Actions/CreateAdminAction.php b/app/Containers/AppSection/User/Actions/CreateAdminAction.php index 7f62368fc..e39d7b96d 100644 --- a/app/Containers/AppSection/User/Actions/CreateAdminAction.php +++ b/app/Containers/AppSection/User/Actions/CreateAdminAction.php @@ -7,7 +7,7 @@ use App\Containers\AppSection\User\Models\User; use App\Ship\Exceptions\CreateResourceFailedException; use App\Ship\Parents\Actions\Action; -use App\Ship\Parents\Exceptions\Exception; +use Exception; use Illuminate\Support\Facades\DB; use Throwable; diff --git a/app/Containers/AppSection/User/Tests/Unit/CreateAdminActionTest.php b/app/Containers/AppSection/User/Tests/Unit/CreateAdminActionTest.php index ebdc50b9b..dbe3eee71 100644 --- a/app/Containers/AppSection/User/Tests/Unit/CreateAdminActionTest.php +++ b/app/Containers/AppSection/User/Tests/Unit/CreateAdminActionTest.php @@ -4,6 +4,7 @@ use App\Containers\AppSection\User\Actions\CreateAdminAction; use App\Containers\AppSection\User\Tests\TestCase; +use Exception; /** * Class CreateAdminActionTest. @@ -27,4 +28,23 @@ public function testCreateAdmin(): void $this->assertTrue($admin->hasRole(config('appSection-authorization.admin_role'))); $this->assertNotNull($admin->email_verified_at); } + + public function testGivenInvalidData_ThrowExceptionAndRollbackAllCommits(): void + { + $this->expectException(Exception::class); + + // update Admin role name to a not existing role (different from what is seeded for admin role), + // so we can get an error + config(['appSection-authorization.admin_role' => 'not_existing_role']); + + $data = [ + 'email' => 'a@new.email', + 'password' => 'admin', + 'name' => 'Super Admin', + ]; + + $admin = app(CreateAdminAction::class)->run($data); + + $this->assertModelMissing($admin); + } }