flowtodo/tests/Feature/Auth/PasswordResetTest.php
Javier Feliz 0ddd325281
Some checks are pending
linter / quality (push) Waiting to run
tests / ci (push) Waiting to run
Initial commit
2025-07-15 18:28:47 -04:00

70 lines
2.0 KiB
PHP

<?php
use App\Livewire\Auth\ForgotPassword;
use App\Livewire\Auth\ResetPassword;
use App\Models\User;
use Illuminate\Auth\Notifications\ResetPassword as ResetPasswordNotification;
use Illuminate\Support\Facades\Notification;
use Livewire\Livewire;
uses(\Illuminate\Foundation\Testing\RefreshDatabase::class);
test('reset password link screen can be rendered', function () {
$response = $this->get('/forgot-password');
$response->assertStatus(200);
});
test('reset password link can be requested', function () {
Notification::fake();
$user = User::factory()->create();
Livewire::test(ForgotPassword::class)
->set('email', $user->email)
->call('sendPasswordResetLink');
Notification::assertSentTo($user, ResetPasswordNotification::class);
});
test('reset password screen can be rendered', function () {
Notification::fake();
$user = User::factory()->create();
Livewire::test(ForgotPassword::class)
->set('email', $user->email)
->call('sendPasswordResetLink');
Notification::assertSentTo($user, ResetPasswordNotification::class, function ($notification) {
$response = $this->get('/reset-password/'.$notification->token);
$response->assertStatus(200);
return true;
});
});
test('password can be reset with valid token', function () {
Notification::fake();
$user = User::factory()->create();
Livewire::test(ForgotPassword::class)
->set('email', $user->email)
->call('sendPasswordResetLink');
Notification::assertSentTo($user, ResetPasswordNotification::class, function ($notification) use ($user) {
$response = Livewire::test(ResetPassword::class, ['token' => $notification->token])
->set('email', $user->email)
->set('password', 'password')
->set('password_confirmation', 'password')
->call('resetPassword');
$response
->assertHasNoErrors()
->assertRedirect(route('login', absolute: false));
return true;
});
});