mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-14 19:22:14 +01:00
Add more tests; Add filter in filament resource; Added options for user create command
This commit is contained in:
committed by
Constantin Graf
parent
84c9cfe2f2
commit
dce608e403
@@ -28,8 +28,10 @@ class OrganizationDeleteCommandTest extends TestCaseWithDatabase
|
||||
});
|
||||
|
||||
// Act
|
||||
$this->artisan('admin:organization:delete', ['organization' => $organization->getKey()])
|
||||
->expectsOutput("Deleting organization with ID {$organization->getKey()}")
|
||||
$command = $this->artisan('admin:organization:delete', ['organization' => $organization->getKey()]);
|
||||
|
||||
// Assert
|
||||
$command->expectsOutput("Deleting organization with ID {$organization->getKey()}")
|
||||
->expectsOutput("Organization with ID {$organization->getKey()} has been deleted.")
|
||||
->assertExitCode(0);
|
||||
}
|
||||
@@ -40,9 +42,11 @@ class OrganizationDeleteCommandTest extends TestCaseWithDatabase
|
||||
$organizationId = Str::uuid()->toString();
|
||||
|
||||
// Act
|
||||
$this->artisan('admin:organization:delete', ['organization' => $organizationId])
|
||||
->expectsOutput('Organization with ID '.$organizationId.' not found.')
|
||||
->assertExitCode(1);
|
||||
$command = $this->artisan('admin:organization:delete', ['organization' => $organizationId]);
|
||||
|
||||
// Assert
|
||||
$command->expectsOutput('Organization with ID '.$organizationId.' not found.');
|
||||
$command->assertExitCode(1);
|
||||
}
|
||||
|
||||
public function test_it_fails_if_organization_id_is_not_a_valid_uuid(): void
|
||||
@@ -51,8 +55,10 @@ class OrganizationDeleteCommandTest extends TestCaseWithDatabase
|
||||
$organizationId = 'invalid-uuid';
|
||||
|
||||
// Act
|
||||
$this->artisan('admin:organization:delete', ['organization' => $organizationId])
|
||||
->expectsOutput('Organization ID must be a valid UUID.')
|
||||
$command = $this->artisan('admin:organization:delete', ['organization' => $organizationId]);
|
||||
|
||||
// Assert
|
||||
$command->expectsOutput('Organization ID must be a valid UUID.')
|
||||
->assertExitCode(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 = 'mail@testuser.test';
|
||||
$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 = 'mail@testuser.test';
|
||||
$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 = 'mail@testuser.test';
|
||||
$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 = 'mail@testuser.test';
|
||||
$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));
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,6 @@ class UserVerifyCommandTest extends TestCaseWithDatabase
|
||||
$command = $this->artisan('admin:user:verify', ['email' => $user->email]);
|
||||
|
||||
// Assert
|
||||
|
||||
$command->expectsOutput('Start verifying user with email "'.$user->email.'"')
|
||||
->expectsOutput('User with email "'.$user->email.'" has been verified.')
|
||||
->assertExitCode(0);
|
||||
|
||||
Reference in New Issue
Block a user