byos_laravel/tests/Feature/Settings/PasswordUpdateTest.php
2026-01-15 23:34:58 +01:00

40 lines
1.1 KiB
PHP

<?php
use App\Models\User;
use Illuminate\Support\Facades\Hash;
uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
test('password can be updated', function (): void {
$user = User::factory()->create([
'password' => Hash::make('password'),
]);
$this->actingAs($user);
$response = Livewire::test('pages::settings.password')
->set('current_password', 'password')
->set('password', 'new-password')
->set('password_confirmation', 'new-password')
->call('updatePassword');
$response->assertHasNoErrors();
$this->assertTrue(Hash::check('new-password', $user->refresh()->password));
});
test('correct password must be provided to update password', function (): void {
$user = User::factory()->create([
'password' => Hash::make('password'),
]);
$this->actingAs($user);
$response = Livewire::test('pages::settings.password')
->set('current_password', 'wrong-password')
->set('password', 'new-password')
->set('password_confirmation', 'new-password')
->call('updatePassword');
$response->assertHasErrors(['current_password']);
});