Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Alavi committed Dec 11, 2021
1 parent 0416e19 commit 68919bb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Containers\AppSection\User\Actions\CreateAdminAction;
use App\Containers\AppSection\User\Tests\TestCase;
use Exception;

/**
* Class CreateAdminActionTest.
Expand All @@ -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' => '[email protected]',
'password' => 'admin',
'name' => 'Super Admin',
];

$admin = app(CreateAdminAction::class)->run($data);

$this->assertModelMissing($admin);
}
}

0 comments on commit 68919bb

Please sign in to comment.