Skip to content

Commit 2a9976b

Browse files
committed
fix Testa and refactor routes names to be consistent
1 parent c8d589b commit 2a9976b

File tree

8 files changed

+47
-83
lines changed

8 files changed

+47
-83
lines changed

resources/views/components/layouts/app/header.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class="flex h-full w-full items-center justify-center rounded-lg bg-neutral-200
7373
<flux:menu.separator />
7474

7575
<flux:menu.radio.group>
76-
<flux:menu.item :href="route('settings.profile')" icon="cog" wire:navigate>{{ __('Settings') }}</flux:menu.item>
76+
<flux:menu.item :href="route('profile.edit')" icon="cog" wire:navigate>{{ __('Settings') }}</flux:menu.item>
7777
</flux:menu.radio.group>
7878

7979
<flux:menu.separator />

resources/views/components/layouts/app/sidebar.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class="flex h-full w-full items-center justify-center rounded-lg bg-neutral-200
6060
<flux:menu.separator />
6161

6262
<flux:menu.radio.group>
63-
<flux:menu.item :href="route('settings.profile')" icon="cog" wire:navigate>{{ __('Settings') }}</flux:menu.item>
63+
<flux:menu.item :href="route('profile.edit')" icon="cog" wire:navigate>{{ __('Settings') }}</flux:menu.item>
6464
</flux:menu.radio.group>
6565

6666
<flux:menu.separator />
@@ -110,7 +110,7 @@ class="flex h-full w-full items-center justify-center rounded-lg bg-neutral-200
110110
<flux:menu.separator />
111111

112112
<flux:menu.radio.group>
113-
<flux:menu.item :href="route('settings.profile')" icon="cog" wire:navigate>{{ __('Settings') }}</flux:menu.item>
113+
<flux:menu.item :href="route('profile.edit')" icon="cog" wire:navigate>{{ __('Settings') }}</flux:menu.item>
114114
</flux:menu.radio.group>
115115

116116
<flux:menu.separator />

resources/views/components/settings/layout.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<div class="flex items-start max-md:flex-col">
22
<div class="me-10 w-full pb-4 md:w-[220px]">
33
<flux:navlist>
4-
<flux:navlist.item :href="route('settings.profile')" wire:navigate>{{ __('Profile') }}</flux:navlist.item>
5-
<flux:navlist.item :href="route('settings.user-password')" wire:navigate>{{ __('Password') }}</flux:navlist.item>
4+
<flux:navlist.item :href="route('profile.edit')" wire:navigate>{{ __('Profile') }}</flux:navlist.item>
5+
<flux:navlist.item :href="route('user-password.edit')" wire:navigate>{{ __('Password') }}</flux:navlist.item>
66
@if (Laravel\Fortify\Features::canManageTwoFactorAuthentication())
77
<flux:navlist.item :href="route('two-factor.show')" wire:navigate>{{ __('Two-Factor Auth') }}</flux:navlist.item>
88
@endif
9-
<flux:navlist.item :href="route('settings.appearance')" wire:navigate>{{ __('Appearance') }}</flux:navlist.item>
9+
<flux:navlist.item :href="route('appearance.edit')" wire:navigate>{{ __('Appearance') }}</flux:navlist.item>
1010
</flux:navlist>
1111
</div>
1212

routes/web.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
Route::middleware(['auth'])->group(function () {
1919
Route::redirect('settings', 'settings/profile');
2020

21-
Route::get('settings/profile', Profile::class)->name('settings.profile');
22-
Route::get('settings/password', Password::class)->name('settings.user-password');
23-
Route::get('settings/appearance', Appearance::class)->name('settings.appearance');
21+
Route::get('settings/profile', Profile::class)->name('profile.edit');
22+
Route::get('settings/password', Password::class)->name('user-password.edit');
23+
Route::get('settings/appearance', Appearance::class)->name('appearance.edit');
2424

2525
Route::get('settings/two-factor', TwoFactor::class)
2626
->middleware(

tests/Feature/Auth/AuthenticationTest.php

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
namespace Tests\Feature\Auth;
44

5-
use App\Livewire\Auth\Login;
65
use App\Models\User;
76
use Illuminate\Foundation\Testing\RefreshDatabase;
87
use Laravel\Fortify\Features;
9-
use Livewire\Livewire;
108
use Tests\TestCase;
119

1210
class AuthenticationTest extends TestCase
@@ -15,22 +13,21 @@ class AuthenticationTest extends TestCase
1513

1614
public function test_login_screen_can_be_rendered(): void
1715
{
18-
$response = $this->get('/login');
19-
16+
$response = $this->get(route('login'));
2017
$response->assertStatus(200);
2118
}
2219

2320
public function test_users_can_authenticate_using_the_login_screen(): void
2421
{
2522
$user = User::factory()->withoutTwoFactor()->create();
2623

27-
$response = Livewire::test(Login::class)
28-
->set('email', $user->email)
29-
->set('password', 'password')
30-
->call('login');
24+
$response = $this->post(route('login.store'), [
25+
'email' => $user->email,
26+
'password' => 'password',
27+
]);
3128

3229
$response
33-
->assertHasNoErrors()
30+
->assertSessionHasNoErrors()
3431
->assertRedirect(route('dashboard', absolute: false));
3532

3633
$this->assertAuthenticated();
@@ -40,12 +37,12 @@ public function test_users_can_not_authenticate_with_invalid_password(): void
4037
{
4138
$user = User::factory()->create();
4239

43-
$response = Livewire::test(Login::class)
44-
->set('email', $user->email)
45-
->set('password', 'wrong-password')
46-
->call('login');
40+
$response = $this->post(route('login.store'), [
41+
'email' => $user->email,
42+
'password' => 'wrong-password',
43+
]);
4744

48-
$response->assertHasErrors('email');
45+
$response->assertSessionHasErrorsIn('email');
4946

5047
$this->assertGuest();
5148
}
@@ -55,38 +52,27 @@ public function test_users_with_two_factor_enabled_are_redirected_to_two_factor_
5552
if (! Features::canManageTwoFactorAuthentication()) {
5653
$this->markTestSkipped('Two-factor authentication is not enabled.');
5754
}
58-
5955
Features::twoFactorAuthentication([
6056
'confirm' => true,
6157
'confirmPassword' => true,
6258
]);
6359

6460
$user = User::factory()->create();
6561

66-
$user->forceFill([
67-
'two_factor_secret' => encrypt('test-secret'),
68-
'two_factor_recovery_codes' => encrypt(json_encode(['code1', 'code2'])),
69-
'two_factor_confirmed_at' => now(),
70-
])->save();
71-
72-
$response = Livewire::test('auth.login')
73-
->set('email', $user->email)
74-
->set('password', 'password')
75-
->call('login');
62+
$response = $this->post(route('login.store'), [
63+
'email' => $user->email,
64+
'password' => 'password',
65+
]);
7666

7767
$response->assertRedirect(route('two-factor.login'));
78-
$response->assertSessionHas('login.id', $user->id);
7968
$this->assertGuest();
8069
}
8170

8271
public function test_users_can_logout(): void
8372
{
8473
$user = User::factory()->create();
85-
86-
$response = $this->actingAs($user)->post('/logout');
87-
88-
$response->assertRedirect('/');
89-
74+
$response = $this->actingAs($user)->post(route('logout'));
75+
$response->assertRedirect(route('home'));
9076
$this->assertGuest();
9177
}
9278
}

tests/Feature/Auth/EmailVerificationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function test_email_verification_screen_can_be_rendered(): void
1717
{
1818
$user = User::factory()->unverified()->create();
1919

20-
$response = $this->actingAs($user)->get('/verify-email');
20+
$response = $this->actingAs($user)->get(route('verification.notice'));
2121

2222
$response->assertStatus(200);
2323
}

tests/Feature/Auth/PasswordResetTest.php

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22

33
namespace Tests\Feature\Auth;
44

5-
use App\Livewire\Auth\ForgotPassword;
6-
use App\Livewire\Auth\ResetPassword;
75
use App\Models\User;
8-
use Illuminate\Auth\Notifications\ResetPassword as ResetPasswordNotification;
6+
use Illuminate\Auth\Notifications\ResetPassword;
97
use Illuminate\Foundation\Testing\RefreshDatabase;
108
use Illuminate\Support\Facades\Notification;
11-
use Livewire\Livewire;
129
use Tests\TestCase;
1310

1411
class PasswordResetTest extends TestCase
@@ -17,8 +14,7 @@ class PasswordResetTest extends TestCase
1714

1815
public function test_reset_password_link_screen_can_be_rendered(): void
1916
{
20-
$response = $this->get('/forgot-password');
21-
17+
$response = $this->get(route('password.request'));
2218
$response->assertStatus(200);
2319
}
2420

@@ -28,11 +24,9 @@ public function test_reset_password_link_can_be_requested(): void
2824

2925
$user = User::factory()->create();
3026

31-
Livewire::test(ForgotPassword::class)
32-
->set('email', $user->email)
33-
->call('sendPasswordResetLink');
27+
$this->post(route('password.request'), ['email' => $user->email]);
3428

35-
Notification::assertSentTo($user, ResetPasswordNotification::class);
29+
Notification::assertSentTo($user, ResetPassword::class);
3630
}
3731

3832
public function test_reset_password_screen_can_be_rendered(): void
@@ -41,13 +35,10 @@ public function test_reset_password_screen_can_be_rendered(): void
4135

4236
$user = User::factory()->create();
4337

44-
Livewire::test(ForgotPassword::class)
45-
->set('email', $user->email)
46-
->call('sendPasswordResetLink');
47-
48-
Notification::assertSentTo($user, ResetPasswordNotification::class, function ($notification) {
49-
$response = $this->get('/reset-password/'.$notification->token);
38+
$this->post(route('password.request'), ['email' => $user->email]);
5039

40+
Notification::assertSentTo($user, ResetPassword::class, function ($notification) {
41+
$response = $this->get(route('password.reset', $notification->token));
5142
$response->assertStatus(200);
5243

5344
return true;
@@ -60,19 +51,18 @@ public function test_password_can_be_reset_with_valid_token(): void
6051

6152
$user = User::factory()->create();
6253

63-
Livewire::test(ForgotPassword::class)
64-
->set('email', $user->email)
65-
->call('sendPasswordResetLink');
54+
$this->post(route('password.request'), ['email' => $user->email]);
6655

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');
56+
Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) {
57+
$response = $this->post(route('password.update'), [
58+
'token' => $notification->token,
59+
'email' => $user->email,
60+
'password' => 'password',
61+
'password_confirmation' => 'password',
62+
]);
7363

7464
$response
75-
->assertHasNoErrors()
65+
->assertSessionHasNoErrors()
7666
->assertRedirect(route('login', absolute: false));
7767

7868
return true;

tests/Feature/Auth/TwoFactorChallengeTest.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use App\Models\User;
66
use Illuminate\Foundation\Testing\RefreshDatabase;
77
use Laravel\Fortify\Features;
8-
use Livewire\Livewire;
98
use Tests\TestCase;
109

1110
class TwoFactorChallengeTest extends TestCase
@@ -17,9 +16,7 @@ public function test_two_factor_challenge_redirects_to_login_when_not_authentica
1716
if (! Features::canManageTwoFactorAuthentication()) {
1817
$this->markTestSkipped('Two-factor authentication is not enabled.');
1918
}
20-
2119
$response = $this->get(route('two-factor.login'));
22-
2320
$response->assertRedirect(route('login'));
2421
}
2522

@@ -28,25 +25,16 @@ public function test_two_factor_challenge_can_be_rendered(): void
2825
if (! Features::canManageTwoFactorAuthentication()) {
2926
$this->markTestSkipped('Two-factor authentication is not enabled.');
3027
}
31-
3228
Features::twoFactorAuthentication([
3329
'confirm' => true,
3430
'confirmPassword' => true,
3531
]);
3632

3733
$user = User::factory()->create();
3834

39-
$user->forceFill([
40-
'two_factor_secret' => encrypt('test-secret'),
41-
'two_factor_recovery_codes' => encrypt(json_encode(['code1', 'code2'])),
42-
'two_factor_confirmed_at' => now(),
43-
])->save();
44-
45-
Livewire::test('auth.login')
46-
->set('email', $user->email)
47-
->set('password', 'password')
48-
->call('login')
49-
->assertRedirect(route('two-factor.login'))
50-
->assertOk();
35+
$this->post(route('login.store'), [
36+
'email' => $user->email,
37+
'password' => 'password',
38+
])->assertRedirect(route('two-factor.login'));
5139
}
5240
}

0 commit comments

Comments
 (0)