Add touch-ready Filament login and admin update tooling
This commit is contained in:
67
tests/Feature/AdminPinLoginTest.php
Normal file
67
tests/Feature/AdminPinLoginTest.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Filament\Pages\Auth\Login;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AdminPinLoginTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Filament::setCurrentPanel('admin');
|
||||
}
|
||||
|
||||
public function test_admin_can_authenticate_with_valid_pin(): void
|
||||
{
|
||||
$user = $this->createAdminUser();
|
||||
$this->assertTrue(Hash::check('1234', $user->admin_pin_hash));
|
||||
|
||||
Livewire::test(Login::class)
|
||||
->call('selectUser', $user->id)
|
||||
->assertSet('data.email', $user->email)
|
||||
->call('appendPinDigit', 1)
|
||||
->call('appendPinDigit', 2)
|
||||
->call('appendPinDigit', 3)
|
||||
->call('appendPinDigit', 4)
|
||||
->assertSet('data.pin', '1234')
|
||||
->call('authenticate')
|
||||
->assertHasNoErrors()
|
||||
->assertRedirect(Filament::getUrl());
|
||||
}
|
||||
|
||||
public function test_admin_cannot_authenticate_with_invalid_pin(): void
|
||||
{
|
||||
$user = $this->createAdminUser();
|
||||
|
||||
Livewire::test(Login::class)
|
||||
->call('selectUser', $user->id)
|
||||
->assertSet('data.email', $user->email)
|
||||
->call('appendPinDigit', 0)
|
||||
->call('appendPinDigit', 0)
|
||||
->call('appendPinDigit', 0)
|
||||
->call('appendPinDigit', 0)
|
||||
->assertSet('data.pin', '0000')
|
||||
->call('authenticate')
|
||||
->assertHasErrors(['data.email']);
|
||||
|
||||
$this->assertGuest();
|
||||
}
|
||||
|
||||
protected function createAdminUser(): User
|
||||
{
|
||||
$role = Role::firstOrCreate(['name' => 'Admin']);
|
||||
|
||||
return User::factory()->create([
|
||||
'role_id' => $role->id,
|
||||
'admin_pin_hash' => Hash::make('1234'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
62
tests/Feature/Filament/EditProfilePinTest.php
Normal file
62
tests/Feature/Filament/EditProfilePinTest.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Filament;
|
||||
|
||||
use App\Filament\Pages\Auth\EditProfile;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EditProfilePinTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Filament::setCurrentPanel('admin');
|
||||
}
|
||||
|
||||
public function test_admin_can_set_pin_from_profile(): void
|
||||
{
|
||||
$user = $this->createAdminUser();
|
||||
$this->actingAs($user);
|
||||
|
||||
Livewire::test(EditProfile::class)
|
||||
->set('data.admin_pin', '4321')
|
||||
->call('save')
|
||||
->assertHasNoErrors();
|
||||
|
||||
$user->refresh();
|
||||
|
||||
$this->assertTrue(Hash::check('4321', $user->admin_pin_hash));
|
||||
}
|
||||
|
||||
public function test_admin_can_remove_pin_from_profile(): void
|
||||
{
|
||||
$user = $this->createAdminUser([
|
||||
'admin_pin_hash' => Hash::make('5678'),
|
||||
]);
|
||||
$this->actingAs($user);
|
||||
|
||||
Livewire::test(EditProfile::class)
|
||||
->set('data.remove_admin_pin', true)
|
||||
->call('save')
|
||||
->assertHasNoErrors();
|
||||
|
||||
$user->refresh();
|
||||
|
||||
$this->assertNull($user->admin_pin_hash);
|
||||
}
|
||||
|
||||
protected function createAdminUser(array $overrides = []): User
|
||||
{
|
||||
$role = Role::firstOrCreate(['name' => 'Admin']);
|
||||
|
||||
return User::factory()->create(array_merge([
|
||||
'role_id' => $role->id,
|
||||
], $overrides));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user