58 lines
1.8 KiB
PHP
58 lines
1.8 KiB
PHP
<?php
|
|
|
|
use App\Enums\IsActive;
|
|
use App\Models\User;
|
|
use Filament\Panel;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
test('user has correct fillable/guarded properties', function () {
|
|
$user = new User;
|
|
expect($user->getGuarded())->toBe(['id']);
|
|
});
|
|
|
|
test('user has correct casts', function () {
|
|
$user = new User;
|
|
expect($user->getCasts())->toHaveKey('password', 'hashed');
|
|
expect($user->getCasts())->toHaveKey('is_active', IsActive::class);
|
|
});
|
|
|
|
test('user can be created using factory', function () {
|
|
$user = User::factory()->create([
|
|
'name' => 'John Doe',
|
|
'email' => 'john@example.com',
|
|
]);
|
|
|
|
expect($user->name)->toBe('John Doe');
|
|
expect(Hash::check('password', $user->password))->toBeTrue();
|
|
$this->assertDatabaseHas('users', ['email' => 'john@example.com']);
|
|
});
|
|
|
|
test('user active scope filters correctly', function () {
|
|
User::factory()->count(2)->create(['is_active' => IsActive::ACTIVE]);
|
|
User::factory()->count(1)->create(['is_active' => IsActive::INACTIVE]);
|
|
|
|
expect(User::active()->count())->toBe(2);
|
|
});
|
|
|
|
test('user can access panel if active', function () {
|
|
$user = User::factory()->create(['is_active' => IsActive::ACTIVE]);
|
|
|
|
// Default mock for Filament Panel if needed, but the method logic is simple
|
|
expect($user->canAccessPanel(mock(Panel::class)))->toBeTrue();
|
|
});
|
|
|
|
test('user cannot access panel if inactive', function () {
|
|
$user = User::factory()->create(['is_active' => IsActive::INACTIVE]);
|
|
|
|
expect($user->canAccessPanel(mock(Panel::class)))->toBeFalse();
|
|
});
|
|
|
|
test('user has company relation', function () {
|
|
$user = User::factory()->create();
|
|
expect($user->company())->toBeInstanceOf(HasOne::class);
|
|
});
|