b2in/tests/Feature/Auth/PasswordResetTest.php
2026-02-20 17:57:50 +01:00

70 lines
2 KiB
PHP

<?php
use App\Models\User;
use App\Notifications\CustomResetPasswordNotification;
use Illuminate\Support\Facades\Notification;
use Livewire\Volt\Volt;
test('reset password link screen can be rendered', function () {
$portalUrl = 'https://'.config('domains.domain_portal');
$response = $this->get($portalUrl.'/forgot-password');
$response->assertStatus(200);
});
test('reset password link can be requested', function () {
Notification::fake();
$user = User::factory()->create();
Volt::test('auth.forgot-password')
->set('email', $user->email)
->call('sendPasswordResetLink');
Notification::assertSentTo($user, CustomResetPasswordNotification::class);
});
test('reset password screen can be rendered', function () {
Notification::fake();
$user = User::factory()->create();
Volt::test('auth.forgot-password')
->set('email', $user->email)
->call('sendPasswordResetLink');
Notification::assertSentTo($user, CustomResetPasswordNotification::class, function ($notification) {
$portalUrl = 'https://'.config('domains.domain_portal');
$response = $this->get($portalUrl.'/reset-password/'.$notification->token);
$response->assertStatus(200);
return true;
});
});
test('password can be reset with valid token', function () {
Notification::fake();
$user = User::factory()->create();
Volt::test('auth.forgot-password')
->set('email', $user->email)
->call('sendPasswordResetLink');
Notification::assertSentTo($user, CustomResetPasswordNotification::class, function ($notification) use ($user) {
$response = Volt::test('auth.reset-password', ['token' => $notification->token])
->set('email', $user->email)
->set('password', 'password')
->set('password_confirmation', 'password')
->call('resetPassword');
$response
->assertHasNoErrors()
->assertRedirect(route('login'));
return true;
});
});