79 lines
2.1 KiB
PHP
79 lines
2.1 KiB
PHP
<?php
|
|
|
|
use App\Livewire\Auth\ForgotPassword;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Password;
|
|
use Livewire\Livewire;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| Helpers
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
|
|
function attemptSendResetLink(string $email)
|
|
{
|
|
return Livewire::test(ForgotPassword::class)
|
|
->set('email', $email)
|
|
->call('sendLink');
|
|
}
|
|
|
|
function mockPasswordResetStatus(string $status, string $email = 'user@example.com'): void
|
|
{
|
|
Password::shouldReceive('sendResetLink')
|
|
->once()
|
|
->with(['email' => $email])
|
|
->andReturn($status);
|
|
}
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| Component Rendering
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
|
|
it('renders forgot password component successfully', function () {
|
|
Livewire::test(ForgotPassword::class)
|
|
->assertViewIs('livewire.auth.forgot-password')
|
|
->assertSet('email', '');
|
|
});
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| Validation Rules
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
|
|
it('validates email field is required', function () {
|
|
Livewire::test(ForgotPassword::class)
|
|
->set('email', '')
|
|
->call('sendLink')
|
|
->assertHasErrors(['email' => 'required']);
|
|
});
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| Send Reset Link
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
|
|
it('sends reset link successfully', function () {
|
|
$email = 'user@example.com';
|
|
|
|
mockPasswordResetStatus(Password::ResetLinkSent, $email);
|
|
|
|
attemptSendResetLink($email)
|
|
->assertHasNoErrors();
|
|
});
|
|
|
|
it('handles failure when sending reset link', function () {
|
|
$email = 'user@example.com';
|
|
|
|
mockPasswordResetStatus('passwords.user', $email);
|
|
|
|
attemptSendResetLink($email)
|
|
->assertHasNoErrors();
|
|
});
|