Skip to content

Commit bbb21d3

Browse files
committed
Refactor routes to redirect to 'home' instead of 'dashboard' in email verification, password confirmation, and registration processes; update tests accordingly and remove unused password update test.
1 parent c14cc97 commit bbb21d3

9 files changed

+75
-93
lines changed

app/Http/Controllers/Auth/VerifyEmailController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class VerifyEmailController extends Controller
1515
public function __invoke(EmailVerificationRequest $request): RedirectResponse
1616
{
1717
if ($request->user()->hasVerifiedEmail()) {
18-
return redirect()->intended(route('dashboard', absolute: false).'?verified=1');
18+
return redirect()->intended(route('home', absolute: false).'?verified=1');
1919
}
2020

2121
if ($request->user()->markEmailAsVerified()) {
@@ -25,6 +25,6 @@ public function __invoke(EmailVerificationRequest $request): RedirectResponse
2525
event(new Verified($user));
2626
}
2727

28-
return redirect()->intended(route('dashboard', absolute: false).'?verified=1');
28+
return redirect()->intended(route('home', absolute: false).'?verified=1');
2929
}
3030
}

app/Livewire/Auth/ConfirmPassword.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ public function confirmPassword(): void
3434

3535
session(['auth.password_confirmed_at' => time()]);
3636

37-
$this->redirectIntended(default: route('dashboard', absolute: false), navigate: true);
37+
$this->redirectIntended(default: route('home', absolute: false), navigate: true);
3838
}
3939
}

app/Livewire/Auth/Register.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ public function register(): void
4949

5050
Auth::login($user);
5151

52-
$this->redirect(route('dashboard', absolute: false), navigate: true);
52+
$this->redirect(route('home', absolute: false), navigate: true);
5353
}
5454
}

app/Livewire/Auth/VerifyEmail.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class VerifyEmail extends Component
1919
public function sendVerification(): void
2020
{
2121
if (Auth::user()->hasVerifiedEmail()) {
22-
$this->redirectIntended(default: route('dashboard', absolute: false), navigate: true);
22+
$this->redirectIntended(default: route('home', absolute: false), navigate: true);
2323

2424
return;
2525
}

tests/Feature/Auth/AuthenticationTest.php

+18-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace Tests\Feature\Auth;
44

5+
use App\Livewire\Auth\Login;
56
use App\Models\User;
67
use Illuminate\Foundation\Testing\RefreshDatabase;
8+
use Livewire\Livewire;
79
use Tests\TestCase;
810

911
class AuthenticationTest extends TestCase
@@ -21,13 +23,24 @@ public function test_users_can_authenticate_using_the_login_screen(): void
2123
{
2224
$user = User::factory()->create();
2325

24-
$response = $this->post('/login', [
25-
'email' => $user->email,
26-
'password' => 'password',
27-
]);
26+
// $response = $this->post('/login', [
27+
// 'email' => $user->email,
28+
// 'password' => 'password',
29+
// ]);
30+
31+
// $this->assertAuthenticated();
32+
// $response->assertRedirect(route('home', absolute: false));
33+
34+
$response = Livewire::test(Login::class)
35+
->set('email', $user->email)
36+
->set('password', 'password')
37+
->call('login');
38+
39+
$response
40+
->assertHasNoErrors()
41+
->assertRedirect(route('frontend.index', absolute: false));
2842

2943
$this->assertAuthenticated();
30-
$response->assertRedirect(route('home', absolute: false));
3144
}
3245

3346
public function test_users_can_not_authenticate_with_invalid_password(): void

tests/Feature/Auth/PasswordConfirmationTest.php

+16-9
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace Tests\Feature\Auth;
44

5+
use App\Livewire\Auth\ConfirmPassword;
56
use App\Models\User;
67
use Illuminate\Foundation\Testing\RefreshDatabase;
8+
use Livewire\Livewire;
79
use Tests\TestCase;
810

911
class PasswordConfirmationTest extends TestCase
@@ -23,22 +25,27 @@ public function test_password_can_be_confirmed(): void
2325
{
2426
$user = User::factory()->create();
2527

26-
$response = $this->actingAs($user)->post('/confirm-password', [
27-
'password' => 'password',
28-
]);
28+
$this->actingAs($user);
2929

30-
$response->assertRedirect();
31-
$response->assertSessionHasNoErrors();
30+
$response = Livewire::test(ConfirmPassword::class)
31+
->set('password', 'password')
32+
->call('confirmPassword');
33+
34+
$response
35+
->assertHasNoErrors()
36+
->assertRedirect(route('home', absolute: false));
3237
}
3338

3439
public function test_password_is_not_confirmed_with_invalid_password(): void
3540
{
3641
$user = User::factory()->create();
3742

38-
$response = $this->actingAs($user)->post('/confirm-password', [
39-
'password' => 'wrong-password',
40-
]);
43+
$this->actingAs($user);
44+
45+
$response = Livewire::test(ConfirmPassword::class)
46+
->set('password', 'wrong-password')
47+
->call('confirmPassword');
4148

42-
$response->assertSessionHasErrors();
49+
$response->assertHasErrors(['password']);
4350
}
4451
}

tests/Feature/Auth/PasswordResetTest.php

+24-16
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
namespace Tests\Feature\Auth;
44

5+
use App\Livewire\Auth\ForgotPassword;
6+
use App\Livewire\Auth\ResetPassword;
57
use App\Models\User;
6-
use Illuminate\Auth\Notifications\ResetPassword;
8+
use Illuminate\Auth\Notifications\ResetPassword as ResetPasswordNotification;
79
use Illuminate\Foundation\Testing\RefreshDatabase;
810
use Illuminate\Support\Facades\Notification;
11+
use Livewire\Livewire;
912
use Tests\TestCase;
1013

1114
class PasswordResetTest extends TestCase
@@ -25,9 +28,11 @@ public function test_reset_password_link_can_be_requested(): void
2528

2629
$user = User::factory()->create();
2730

28-
$this->post('/forgot-password', ['email' => $user->email]);
31+
Livewire::test(ForgotPassword::class)
32+
->set('email', $user->email)
33+
->call('sendPasswordResetLink');
2934

30-
Notification::assertSentTo($user, ResetPassword::class);
35+
Notification::assertSentTo($user, ResetPasswordNotification::class);
3136
}
3237

3338
public function test_reset_password_screen_can_be_rendered(): void
@@ -36,10 +41,12 @@ public function test_reset_password_screen_can_be_rendered(): void
3641

3742
$user = User::factory()->create();
3843

39-
$this->post('/forgot-password', ['email' => $user->email]);
44+
Livewire::test(ForgotPassword::class)
45+
->set('email', $user->email)
46+
->call('sendPasswordResetLink');
4047

41-
Notification::assertSentTo($user, ResetPassword::class, function ($notification) {
42-
$response = $this->get('/reset-password/'.$notification->token);
48+
Notification::assertSentTo($user, ResetPasswordNotification::class, function ($notification) {
49+
$response = $this->get('/reset-password/' . $notification->token);
4350

4451
$response->assertStatus(200);
4552

@@ -53,19 +60,20 @@ public function test_password_can_be_reset_with_valid_token(): void
5360

5461
$user = User::factory()->create();
5562

56-
$this->post('/forgot-password', ['email' => $user->email]);
63+
Livewire::test(ForgotPassword::class)
64+
->set('email', $user->email)
65+
->call('sendPasswordResetLink');
5766

58-
Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) {
59-
$response = $this->post('/reset-password', [
60-
'token' => $notification->token,
61-
'email' => $user->email,
62-
'password' => 'password',
63-
'password_confirmation' => 'password',
64-
]);
67+
Notification::assertSentTo($user, ResetPasswordNotification::class, function ($notification) use ($user) {
68+
$response = Livewire::test(ResetPassword::class, ['token' => $notification->token])
69+
->set('email', $user->email)
70+
->set('password', 'password')
71+
->set('password_confirmation', 'password')
72+
->call('resetPassword');
6573

6674
$response
67-
->assertSessionHasNoErrors()
68-
->assertRedirect(route('login'));
75+
->assertHasNoErrors()
76+
->assertRedirect(route('login', absolute: false));
6977

7078
return true;
7179
});

tests/Feature/Auth/PasswordUpdateTest.php

-51
This file was deleted.

tests/Feature/Auth/RegistrationTest.php

+12-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace Tests\Feature\Auth;
44

5+
use App\Livewire\Auth\Register;
56
use Illuminate\Foundation\Testing\RefreshDatabase;
7+
use Livewire\Livewire;
68
use Tests\TestCase;
79

810
class RegistrationTest extends TestCase
@@ -23,15 +25,18 @@ public function test_registration_screen_can_be_rendered(): void
2325
public function test_new_users_can_register(): void
2426
{
2527
if (config('app.user_registration')) {
26-
$response = $this->post('/register', [
27-
'name' => 'Test User',
28-
'email' => '[email protected]',
29-
'password' => 'password',
30-
'password_confirmation' => 'password',
31-
]);
28+
$response = Livewire::test(Register::class)
29+
->set('name', 'Test User')
30+
->set('email', '[email protected]')
31+
->set('password', 'password')
32+
->set('password_confirmation', 'password')
33+
->call('register');
34+
35+
$response
36+
->assertHasNoErrors()
37+
->assertRedirect(route('home', absolute: false));
3238

3339
$this->assertAuthenticated();
34-
$response->assertRedirect(route('home', absolute: false));
3540
} else {
3641
$response = $this->get('/register');
3742
$response->assertStatus(404);

0 commit comments

Comments
 (0)