Skip to content

Commit 2738d72

Browse files
committed
Fixes and consistency in tests
- Use `route` helper in tests - Use `assertOk` shorthand in tests - Make the "forgot password" routes declaration follow the previous ones for consistency
1 parent 465c3c4 commit 2738d72

File tree

13 files changed

+42
-50
lines changed

13 files changed

+42
-50
lines changed

resources/js/pages/auth/forgot-password.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default function ForgotPassword({ status }: { status?: string }) {
1717
const submit: FormEventHandler = (e) => {
1818
e.preventDefault();
1919

20-
post(route('password.email'));
20+
post(route('password.request'));
2121
};
2222

2323
return (

resources/js/pages/auth/login.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export default function Login({ status, canResetPassword }: LoginProps) {
3030

3131
const submit: FormEventHandler = (e) => {
3232
e.preventDefault();
33+
3334
post(route('login'), {
3435
onFinish: () => reset('password'),
3536
});

resources/js/pages/auth/register.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export default function Register() {
2626

2727
const submit: FormEventHandler = (e) => {
2828
e.preventDefault();
29+
2930
post(route('register'), {
3031
onFinish: () => reset('password', 'password_confirmation'),
3132
});

resources/js/pages/auth/reset-password.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ type ResetPasswordForm = {
2222

2323
export default function ResetPassword({ token, email }: ResetPasswordProps) {
2424
const { data, setData, post, processing, errors, reset } = useForm<Required<ResetPasswordForm>>({
25-
token: token,
26-
email: email,
25+
token,
26+
email,
2727
password: '',
2828
password_confirmation: '',
2929
});
3030

3131
const submit: FormEventHandler = (e) => {
3232
e.preventDefault();
33+
3334
post(route('password.store'), {
3435
onFinish: () => reset('password', 'password_confirmation'),
3536
});

routes/auth.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
Route::get('forgot-password', [PasswordResetLinkController::class, 'create'])
2525
->name('password.request');
2626

27-
Route::post('forgot-password', [PasswordResetLinkController::class, 'store'])
28-
->name('password.email');
27+
Route::post('forgot-password', [PasswordResetLinkController::class, 'store']);
2928

3029
Route::get('reset-password/{token}', [NewPasswordController::class, 'create'])
3130
->name('password.reset');

tests/Feature/Auth/AuthenticationTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@ class AuthenticationTest extends TestCase
1212

1313
public function test_login_screen_can_be_rendered()
1414
{
15-
$response = $this->get('/login');
16-
17-
$response->assertStatus(200);
15+
$this->get(route('login'))->assertOk();
1816
}
1917

2018
public function test_users_can_authenticate_using_the_login_screen()
2119
{
2220
$user = User::factory()->create();
2321

24-
$response = $this->post('/login', [
22+
$response = $this->post(route('login'), [
2523
'email' => $user->email,
2624
'password' => 'password',
2725
]);
@@ -34,7 +32,7 @@ public function test_users_can_not_authenticate_with_invalid_password()
3432
{
3533
$user = User::factory()->create();
3634

37-
$this->post('/login', [
35+
$this->post(route('login'), [
3836
'email' => $user->email,
3937
'password' => 'wrong-password',
4038
]);
@@ -46,7 +44,7 @@ public function test_users_can_logout()
4644
{
4745
$user = User::factory()->create();
4846

49-
$response = $this->actingAs($user)->post('/logout');
47+
$response = $this->actingAs($user)->post(route('logout'));
5048

5149
$this->assertGuest();
5250
$response->assertRedirect('/');

tests/Feature/Auth/EmailVerificationTest.php

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

20-
$response = $this->actingAs($user)->get('/verify-email');
21-
22-
$response->assertStatus(200);
20+
$this->actingAs($user)->get(route('verification.notice'))->assertOk();
2321
}
2422

2523
public function test_email_can_be_verified()

tests/Feature/Auth/PasswordConfirmationTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,14 @@ public function test_confirm_password_screen_can_be_rendered()
1414
{
1515
$user = User::factory()->create();
1616

17-
$response = $this->actingAs($user)->get('/confirm-password');
18-
19-
$response->assertStatus(200);
17+
$this->actingAs($user)->get(route('password.confirm'))->assertOk();
2018
}
2119

2220
public function test_password_can_be_confirmed()
2321
{
2422
$user = User::factory()->create();
2523

26-
$response = $this->actingAs($user)->post('/confirm-password', [
24+
$response = $this->actingAs($user)->post(route('password.confirm'), [
2725
'password' => 'password',
2826
]);
2927

@@ -35,7 +33,7 @@ public function test_password_is_not_confirmed_with_invalid_password()
3533
{
3634
$user = User::factory()->create();
3735

38-
$response = $this->actingAs($user)->post('/confirm-password', [
36+
$response = $this->actingAs($user)->post(route('password.confirm'), [
3937
'password' => 'wrong-password',
4038
]);
4139

tests/Feature/Auth/PasswordResetTest.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ class PasswordResetTest extends TestCase
1414

1515
public function test_reset_password_link_screen_can_be_rendered()
1616
{
17-
$response = $this->get('/forgot-password');
18-
19-
$response->assertStatus(200);
17+
$this->get(route('password.request'))->assertOk();
2018
}
2119

2220
public function test_reset_password_link_can_be_requested()
@@ -25,7 +23,7 @@ public function test_reset_password_link_can_be_requested()
2523

2624
$user = User::factory()->create();
2725

28-
$this->post('/forgot-password', ['email' => $user->email]);
26+
$this->post(route('password.request'), ['email' => $user->email]);
2927

3028
Notification::assertSentTo($user, ResetPassword::class);
3129
}
@@ -36,12 +34,12 @@ public function test_reset_password_screen_can_be_rendered()
3634

3735
$user = User::factory()->create();
3836

39-
$this->post('/forgot-password', ['email' => $user->email]);
37+
$this->post(route('password.request'), ['email' => $user->email]);
4038

4139
Notification::assertSentTo($user, ResetPassword::class, function ($notification) {
42-
$response = $this->get('/reset-password/'.$notification->token);
40+
$response = $this->get(route('password.reset', ['token' => $notification->token]));
4341

44-
$response->assertStatus(200);
42+
$response->assertOk();
4543

4644
return true;
4745
});
@@ -53,10 +51,10 @@ public function test_password_can_be_reset_with_valid_token()
5351

5452
$user = User::factory()->create();
5553

56-
$this->post('/forgot-password', ['email' => $user->email]);
54+
$this->post(route('password.request'), ['email' => $user->email]);
5755

5856
Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) {
59-
$response = $this->post('/reset-password', [
57+
$response = $this->post(route('password.store'), [
6058
'token' => $notification->token,
6159
'email' => $user->email,
6260
'password' => 'password',
@@ -65,7 +63,7 @@ public function test_password_can_be_reset_with_valid_token()
6563

6664
$response
6765
->assertSessionHasNoErrors()
68-
->assertRedirect(route('login'));
66+
->assertRedirectToRoute('login');
6967

7068
return true;
7169
});

tests/Feature/Auth/RegistrationTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@ class RegistrationTest extends TestCase
1111

1212
public function test_registration_screen_can_be_rendered()
1313
{
14-
$response = $this->get('/register');
15-
16-
$response->assertStatus(200);
14+
$this->get(route('register'))->assertOk();
1715
}
1816

1917
public function test_new_users_can_register()
2018
{
21-
$response = $this->post('/register', [
19+
$response = $this->post(route('register'), [
2220
'name' => 'Test User',
2321
'email' => '[email protected]',
2422
'password' => 'password',

0 commit comments

Comments
 (0)