-
-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more tests; Add filter in filament resource; Added options for us…
…er create command
- Loading branch information
Showing
20 changed files
with
413 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
tests/Unit/Console/Commands/Admin/UserCreateCommandCommandTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Unit\Console\Commands\Admin; | ||
|
||
use App\Console\Commands\Admin\UserCreateCommand; | ||
use App\Models\User; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\Artisan; | ||
use Illuminate\Support\Facades\Hash; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\UsesClass; | ||
use Tests\TestCaseWithDatabase; | ||
|
||
#[CoversClass(UserCreateCommand::class)] | ||
#[UsesClass(UserCreateCommand::class)] | ||
class UserCreateCommandCommandTest extends TestCaseWithDatabase | ||
{ | ||
public function test_it_creates_user(): void | ||
{ | ||
// Arrange | ||
$email = '[email protected]'; | ||
$name = 'Test User'; | ||
|
||
// Act | ||
$exitCode = $this->withoutMockingConsoleOutput()->artisan('admin:user:create', [ | ||
'name' => $name, | ||
'email' => $email, | ||
]); | ||
|
||
// Assert | ||
$this->assertSame(Command::SUCCESS, $exitCode); | ||
$output = Artisan::output(); | ||
$this->assertStringContainsString('Created user "'.$name.'" ("'.$email.'")', $output); | ||
$this->assertDatabaseHas(User::class, [ | ||
'name' => $name, | ||
'email' => $email, | ||
'email_verified_at' => null, | ||
]); | ||
} | ||
|
||
public function test_created_user_is_verified_if_option_is_set(): void | ||
{ | ||
// Arrange | ||
$email = '[email protected]'; | ||
$name = 'Test User'; | ||
|
||
// Act | ||
$exitCode = $this->withoutMockingConsoleOutput()->artisan('admin:user:create', [ | ||
'name' => $name, | ||
'email' => $email, | ||
'--verify-email' => true, | ||
]); | ||
|
||
// Assert | ||
$this->assertSame(Command::SUCCESS, $exitCode); | ||
$output = Artisan::output(); | ||
$this->assertStringContainsString('Created user "'.$name.'" ("'.$email.'")', $output); | ||
$this->assertDatabaseHas(User::class, [ | ||
'name' => $name, | ||
'email' => $email, | ||
]); | ||
$user = User::where('email', $email)->first(); | ||
$this->assertNotNull($user->email_verified_at); | ||
} | ||
|
||
public function test_it_fails_if_user_with_email_already_exists(): void | ||
{ | ||
// Arrange | ||
$email = '[email protected]'; | ||
$name = 'Test User'; | ||
|
||
User::factory()->create([ | ||
'email' => $email, | ||
]); | ||
|
||
// Act | ||
$exitCode = $this->withoutMockingConsoleOutput()->artisan('admin:user:create', [ | ||
'name' => $name, | ||
'email' => $email, | ||
]); | ||
|
||
// Assert | ||
$this->assertSame(Command::FAILURE, $exitCode); | ||
$output = Artisan::output(); | ||
$this->assertStringContainsString('User with email "'.$email.'" already exists.', $output); | ||
} | ||
|
||
public function test_it_asks_for_password_if_option_is_set(): void | ||
{ | ||
// Arrange | ||
$email = '[email protected]'; | ||
$name = 'Test User'; | ||
|
||
// Act | ||
$this->artisan('admin:user:create', [ | ||
'name' => $name, | ||
'email' => $email, | ||
'--ask-for-password' => true, | ||
]) | ||
->expectsQuestion('Enter the password', 'password') | ||
->assertExitCode(Command::SUCCESS); | ||
|
||
$this->assertDatabaseHas(User::class, [ | ||
'name' => $name, | ||
'email' => $email, | ||
'email_verified_at' => null, | ||
]); | ||
$user = User::where('email', $email)->first(); | ||
$this->assertNotNull($user->password); | ||
$this->assertTrue(Hash::check('password', $user->password)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
tests/Unit/Filament/Resources/OrganizationInvitationResourceTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Unit\Filament\Resources; | ||
|
||
use App\Filament\Resources\OrganizationInvitationResource; | ||
use App\Models\Organization; | ||
use App\Models\OrganizationInvitation; | ||
use App\Models\User; | ||
use Filament\Actions\DeleteAction; | ||
use Illuminate\Support\Facades\Config; | ||
use Livewire\Livewire; | ||
use PHPUnit\Framework\Attributes\UsesClass; | ||
use Tests\Unit\Filament\FilamentTestCase; | ||
|
||
#[UsesClass(OrganizationInvitationResource::class)] | ||
class OrganizationInvitationResourceTest extends FilamentTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
Config::set('auth.super_admins', ['[email protected]']); | ||
$user = User::factory()->withPersonalOrganization()->create([ | ||
'email' => '[email protected]', | ||
]); | ||
|
||
$this->actingAs($user); | ||
} | ||
|
||
public function test_can_list_organization_invitations(): void | ||
{ | ||
// Arrange | ||
$user = User::factory()->create(); | ||
$organization = Organization::factory()->withOwner($user)->create(); | ||
$organizationInvitations = OrganizationInvitation::factory()->forOrganization($organization)->createMany(5); | ||
|
||
// Act | ||
$response = Livewire::test(OrganizationInvitationResource\Pages\ListOrganizationInvitations::class); | ||
|
||
// Assert | ||
$response->assertSuccessful(); | ||
$response->assertCanSeeTableRecords($organizationInvitations); | ||
} | ||
|
||
public function test_can_see_edit_page_of_organization_invitation(): void | ||
{ | ||
// Arrange | ||
$organization = Organization::factory()->create(); | ||
$organizationInvitation = OrganizationInvitation::factory()->forOrganization($organization)->create(); | ||
|
||
// Act | ||
$response = Livewire::test(OrganizationInvitationResource\Pages\EditOrganizationInvitation::class, [ | ||
'record' => $organizationInvitation->getKey(), | ||
]); | ||
|
||
// Assert | ||
$response->assertSuccessful(); | ||
} | ||
|
||
public function test_can_delete_a_organization_invitation(): void | ||
{ | ||
// Arrange | ||
$organization = Organization::factory()->create(); | ||
$organizationInvitation = OrganizationInvitation::factory()->forOrganization($organization)->create(); | ||
|
||
// Act | ||
$response = Livewire::test(OrganizationInvitationResource\Pages\EditOrganizationInvitation::class, [ | ||
'record' => $organizationInvitation->getKey(), | ||
])->callAction(DeleteAction::class); | ||
|
||
// Assert | ||
$response->assertSuccessful(); | ||
$this->assertDatabaseMissing(OrganizationInvitation::class, [ | ||
'id' => $organizationInvitation->getKey(), | ||
]); | ||
} | ||
} |
Oops, something went wrong.