feat: create user command
CI / 🧪 Tests Laravel (push) Successful in 2m7s
CI / 🐳 Build & Push Image (push) Successful in 37s

This commit is contained in:
2026-08-07 15:01:50 +02:00
parent 909e32523d
commit eac86afa53
2 changed files with 142 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
<?php
use App\Enums\UserRole;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Hash;
uses(RefreshDatabase::class);
it('creates a verified administrator with the application command', function () {
$this->artisan('user:create', [
'--name' => 'admin.bowli',
'--email' => 'ADMIN@EXAMPLE.COM',
'--role' => UserRole::ADMIN->value,
'--locale' => 'fr',
'--verified' => true,
])
->expectsQuestion('Password', 'Strong-password1')
->expectsQuestion('Confirm password', 'Strong-password1')
->assertSuccessful();
$user = User::query()->where('email', 'admin@example.com')->firstOrFail();
expect($user->name)->toBe('admin.bowli')
->and($user->role)->toBe(UserRole::ADMIN)
->and($user->locale)->toBe('fr')
->and($user->email_verified_at)->not->toBeNull()
->and($user->trial_ends_at)->not->toBeNull()
->and(Hash::check('Strong-password1', $user->password))->toBeTrue();
});
it('rejects duplicate users', function () {
User::factory()->create([
'name' => 'existing.user',
'email' => 'existing@example.com',
]);
$this->artisan('user:create', [
'--name' => 'existing.user',
'--email' => 'existing@example.com',
'--role' => UserRole::USER->value,
])->assertFailed();
expect(User::query()->count())->toBe(1);
});