From 57a171b6a2bd8e4e7ecd08bc65729bf61a1409b6 Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Thu, 30 Apr 2026 08:49:34 +0700 Subject: [PATCH] refactor: remove feature tests for authentication and dashboard functionality --- tests/Feature/Auth/AuthenticationTest.php | 82 ------------- tests/Feature/Auth/EmailVerificationTest.php | 100 --------------- .../Feature/Auth/PasswordConfirmationTest.php | 22 ---- tests/Feature/Auth/PasswordResetTest.php | 78 ------------ tests/Feature/Auth/RegistrationTest.php | 25 ---- tests/Feature/Auth/TwoFactorChallengeTest.php | 41 ------- .../Auth/VerificationNotificationTest.php | 34 ------ tests/Feature/DashboardTest.php | 16 --- tests/Feature/Settings/ProfileUpdateTest.php | 85 ------------- tests/Feature/Settings/SecurityTest.php | 114 ------------------ 10 files changed, 597 deletions(-) delete mode 100644 tests/Feature/Auth/AuthenticationTest.php delete mode 100644 tests/Feature/Auth/EmailVerificationTest.php delete mode 100644 tests/Feature/Auth/PasswordConfirmationTest.php delete mode 100644 tests/Feature/Auth/PasswordResetTest.php delete mode 100644 tests/Feature/Auth/RegistrationTest.php delete mode 100644 tests/Feature/Auth/TwoFactorChallengeTest.php delete mode 100644 tests/Feature/Auth/VerificationNotificationTest.php delete mode 100644 tests/Feature/DashboardTest.php delete mode 100644 tests/Feature/Settings/ProfileUpdateTest.php delete mode 100644 tests/Feature/Settings/SecurityTest.php diff --git a/tests/Feature/Auth/AuthenticationTest.php b/tests/Feature/Auth/AuthenticationTest.php deleted file mode 100644 index 4a3817c..0000000 --- a/tests/Feature/Auth/AuthenticationTest.php +++ /dev/null @@ -1,82 +0,0 @@ -get(route('login')); - - $response->assertOk(); -}); - -test('users can authenticate using the login screen', function () { - $user = User::factory()->create(); - - $response = $this->post(route('login.store'), [ - 'email' => $user->email, - 'password' => 'password', - ]); - - $this->assertAuthenticated(); - $response->assertRedirect(route('dashboard', absolute: false)); -}); - -test('users with two factor enabled are redirected to two factor challenge', function () { - $this->skipUnlessFortifyHas(Features::twoFactorAuthentication()); - - Features::twoFactorAuthentication([ - 'confirm' => true, - 'confirmPassword' => true, - ]); - - $user = User::factory()->create(); - - $user->forceFill([ - 'two_factor_secret' => encrypt('test-secret'), - 'two_factor_recovery_codes' => encrypt(json_encode(['code1', 'code2'])), - 'two_factor_confirmed_at' => now(), - ])->save(); - - $response = $this->post(route('login'), [ - 'email' => $user->email, - 'password' => 'password', - ]); - - $response->assertRedirect(route('two-factor.login')); - $response->assertSessionHas('login.id', $user->id); - $this->assertGuest(); -}); - -test('users can not authenticate with invalid password', function () { - $user = User::factory()->create(); - - $this->post(route('login.store'), [ - 'email' => $user->email, - 'password' => 'wrong-password', - ]); - - $this->assertGuest(); -}); - -test('users can logout', function () { - $user = User::factory()->create(); - - $response = $this->actingAs($user)->post(route('logout')); - - $this->assertGuest(); - $response->assertRedirect(route('home')); -}); - -test('users are rate limited', function () { - $user = User::factory()->create(); - - RateLimiter::increment(md5('login'.implode('|', [$user->email, '127.0.0.1'])), amount: 5); - - $response = $this->post(route('login.store'), [ - 'email' => $user->email, - 'password' => 'wrong-password', - ]); - - $response->assertTooManyRequests(); -}); diff --git a/tests/Feature/Auth/EmailVerificationTest.php b/tests/Feature/Auth/EmailVerificationTest.php deleted file mode 100644 index 84b8dfc..0000000 --- a/tests/Feature/Auth/EmailVerificationTest.php +++ /dev/null @@ -1,100 +0,0 @@ -skipUnlessFortifyHas(Features::emailVerification()); -}); - -test('email verification screen can be rendered', function () { - $user = User::factory()->unverified()->create(); - - $response = $this->actingAs($user)->get(route('verification.notice')); - - $response->assertOk(); -}); - -test('email can be verified', function () { - $user = User::factory()->unverified()->create(); - - Event::fake(); - - $verificationUrl = URL::temporarySignedRoute( - 'verification.verify', - now()->addMinutes(60), - ['id' => $user->id, 'hash' => sha1($user->email)], - ); - - $response = $this->actingAs($user)->get($verificationUrl); - - Event::assertDispatched(Verified::class); - expect($user->fresh()->hasVerifiedEmail())->toBeTrue(); - $response->assertRedirect(route('dashboard', absolute: false).'?verified=1'); -}); - -test('email is not verified with invalid hash', function () { - $user = User::factory()->unverified()->create(); - - Event::fake(); - - $verificationUrl = URL::temporarySignedRoute( - 'verification.verify', - now()->addMinutes(60), - ['id' => $user->id, 'hash' => sha1('wrong-email')], - ); - - $this->actingAs($user)->get($verificationUrl); - - Event::assertNotDispatched(Verified::class); - expect($user->fresh()->hasVerifiedEmail())->toBeFalse(); -}); - -test('email is not verified with invalid user id', function () { - $user = User::factory()->unverified()->create(); - - Event::fake(); - - $verificationUrl = URL::temporarySignedRoute( - 'verification.verify', - now()->addMinutes(60), - ['id' => 123, 'hash' => sha1($user->email)], - ); - - $this->actingAs($user)->get($verificationUrl); - - Event::assertNotDispatched(Verified::class); - expect($user->fresh()->hasVerifiedEmail())->toBeFalse(); -}); - -test('verified user is redirected to dashboard from verification prompt', function () { - $user = User::factory()->create(); - - Event::fake(); - - $response = $this->actingAs($user)->get(route('verification.notice')); - - Event::assertNotDispatched(Verified::class); - $response->assertRedirect(route('dashboard', absolute: false)); -}); - -test('already verified user visiting verification link is redirected without firing event again', function () { - $user = User::factory()->create(); - - Event::fake(); - - $verificationUrl = URL::temporarySignedRoute( - 'verification.verify', - now()->addMinutes(60), - ['id' => $user->id, 'hash' => sha1($user->email)], - ); - - $this->actingAs($user)->get($verificationUrl) - ->assertRedirect(route('dashboard', absolute: false).'?verified=1'); - - Event::assertNotDispatched(Verified::class); - expect($user->fresh()->hasVerifiedEmail())->toBeTrue(); -}); diff --git a/tests/Feature/Auth/PasswordConfirmationTest.php b/tests/Feature/Auth/PasswordConfirmationTest.php deleted file mode 100644 index 5d58992..0000000 --- a/tests/Feature/Auth/PasswordConfirmationTest.php +++ /dev/null @@ -1,22 +0,0 @@ -create(); - - $response = $this->actingAs($user)->get(route('password.confirm')); - - $response->assertOk(); - - $response->assertInertia(fn (Assert $page) => $page - ->component('auth/confirm-password'), - ); -}); - -test('password confirmation requires authentication', function () { - $response = $this->get(route('password.confirm')); - - $response->assertRedirect(route('login')); -}); diff --git a/tests/Feature/Auth/PasswordResetTest.php b/tests/Feature/Auth/PasswordResetTest.php deleted file mode 100644 index a2b8010..0000000 --- a/tests/Feature/Auth/PasswordResetTest.php +++ /dev/null @@ -1,78 +0,0 @@ -skipUnlessFortifyHas(Features::resetPasswords()); -}); - -test('reset password link screen can be rendered', function () { - $response = $this->get(route('password.request')); - - $response->assertOk(); -}); - -test('reset password link can be requested', function () { - Notification::fake(); - - $user = User::factory()->create(); - - $this->post(route('password.email'), ['email' => $user->email]); - - Notification::assertSentTo($user, ResetPassword::class); -}); - -test('reset password screen can be rendered', function () { - Notification::fake(); - - $user = User::factory()->create(); - - $this->post(route('password.email'), ['email' => $user->email]); - - Notification::assertSentTo($user, ResetPassword::class, function ($notification) { - $response = $this->get(route('password.reset', $notification->token)); - - $response->assertOk(); - - return true; - }); -}); - -test('password can be reset with valid token', function () { - Notification::fake(); - - $user = User::factory()->create(); - - $this->post(route('password.email'), ['email' => $user->email]); - - Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) { - $response = $this->post(route('password.update'), [ - 'token' => $notification->token, - 'email' => $user->email, - 'password' => 'password', - 'password_confirmation' => 'password', - ]); - - $response - ->assertSessionHasNoErrors() - ->assertRedirect(route('login')); - - return true; - }); -}); - -test('password cannot be reset with invalid token', function () { - $user = User::factory()->create(); - - $response = $this->post(route('password.update'), [ - 'token' => 'invalid-token', - 'email' => $user->email, - 'password' => 'newpassword123', - 'password_confirmation' => 'newpassword123', - ]); - - $response->assertSessionHasErrors('email'); -}); diff --git a/tests/Feature/Auth/RegistrationTest.php b/tests/Feature/Auth/RegistrationTest.php deleted file mode 100644 index 35ec7ca..0000000 --- a/tests/Feature/Auth/RegistrationTest.php +++ /dev/null @@ -1,25 +0,0 @@ -skipUnlessFortifyHas(Features::registration()); -}); - -test('registration screen can be rendered', function () { - $response = $this->get(route('register')); - - $response->assertOk(); -}); - -test('new users can register', function () { - $response = $this->post(route('register.store'), [ - 'name' => 'Test User', - 'email' => 'test@example.com', - 'password' => 'password', - 'password_confirmation' => 'password', - ]); - - $this->assertAuthenticated(); - $response->assertRedirect(route('dashboard', absolute: false)); -}); diff --git a/tests/Feature/Auth/TwoFactorChallengeTest.php b/tests/Feature/Auth/TwoFactorChallengeTest.php deleted file mode 100644 index 7e4e5f5..0000000 --- a/tests/Feature/Auth/TwoFactorChallengeTest.php +++ /dev/null @@ -1,41 +0,0 @@ -skipUnlessFortifyHas(Features::twoFactorAuthentication()); -}); - -test('two factor challenge redirects to login when not authenticated', function () { - $response = $this->get(route('two-factor.login')); - - $response->assertRedirect(route('login')); -}); - -test('two factor challenge can be rendered', function () { - Features::twoFactorAuthentication([ - 'confirm' => true, - 'confirmPassword' => true, - ]); - - $user = User::factory()->create(); - - $user->forceFill([ - 'two_factor_secret' => encrypt('test-secret'), - 'two_factor_recovery_codes' => encrypt(json_encode(['code1', 'code2'])), - 'two_factor_confirmed_at' => now(), - ])->save(); - - $this->post(route('login'), [ - 'email' => $user->email, - 'password' => 'password', - ]); - - $this->get(route('two-factor.login')) - ->assertOk() - ->assertInertia(fn (Assert $page) => $page - ->component('auth/two-factor-challenge'), - ); -}); diff --git a/tests/Feature/Auth/VerificationNotificationTest.php b/tests/Feature/Auth/VerificationNotificationTest.php deleted file mode 100644 index 2e7c33f..0000000 --- a/tests/Feature/Auth/VerificationNotificationTest.php +++ /dev/null @@ -1,34 +0,0 @@ -skipUnlessFortifyHas(Features::emailVerification()); -}); - -test('sends verification notification', function () { - Notification::fake(); - - $user = User::factory()->unverified()->create(); - - $this->actingAs($user) - ->post(route('verification.send')) - ->assertRedirect(route('home')); - - Notification::assertSentTo($user, VerifyEmail::class); -}); - -test('does not send verification notification if email is verified', function () { - Notification::fake(); - - $user = User::factory()->create(); - - $this->actingAs($user) - ->post(route('verification.send')) - ->assertRedirect(route('dashboard', absolute: false)); - - Notification::assertNothingSent(); -}); diff --git a/tests/Feature/DashboardTest.php b/tests/Feature/DashboardTest.php deleted file mode 100644 index 95c6a8b..0000000 --- a/tests/Feature/DashboardTest.php +++ /dev/null @@ -1,16 +0,0 @@ -get(route('dashboard')); - $response->assertRedirect(route('login')); -}); - -test('authenticated users can visit the dashboard', function () { - $user = User::factory()->create(); - $this->actingAs($user); - - $response = $this->get(route('dashboard')); - $response->assertOk(); -}); diff --git a/tests/Feature/Settings/ProfileUpdateTest.php b/tests/Feature/Settings/ProfileUpdateTest.php deleted file mode 100644 index 9f49e25..0000000 --- a/tests/Feature/Settings/ProfileUpdateTest.php +++ /dev/null @@ -1,85 +0,0 @@ -create(); - - $response = $this - ->actingAs($user) - ->get(route('profile.edit')); - - $response->assertOk(); -}); - -test('profile information can be updated', function () { - $user = User::factory()->create(); - - $response = $this - ->actingAs($user) - ->patch(route('profile.update'), [ - 'name' => 'Test User', - 'email' => 'test@example.com', - ]); - - $response - ->assertSessionHasNoErrors() - ->assertRedirect(route('profile.edit')); - - $user->refresh(); - - expect($user->name)->toBe('Test User'); - expect($user->email)->toBe('test@example.com'); - expect($user->email_verified_at)->toBeNull(); -}); - -test('email verification status is unchanged when the email address is unchanged', function () { - $user = User::factory()->create(); - - $response = $this - ->actingAs($user) - ->patch(route('profile.update'), [ - 'name' => 'Test User', - 'email' => $user->email, - ]); - - $response - ->assertSessionHasNoErrors() - ->assertRedirect(route('profile.edit')); - - expect($user->refresh()->email_verified_at)->not->toBeNull(); -}); - -test('user can delete their account', function () { - $user = User::factory()->create(); - - $response = $this - ->actingAs($user) - ->delete(route('profile.destroy'), [ - 'password' => 'password', - ]); - - $response - ->assertSessionHasNoErrors() - ->assertRedirect(route('home')); - - $this->assertGuest(); - expect($user->fresh())->toBeNull(); -}); - -test('correct password must be provided to delete account', function () { - $user = User::factory()->create(); - - $response = $this - ->actingAs($user) - ->from(route('profile.edit')) - ->delete(route('profile.destroy'), [ - 'password' => 'wrong-password', - ]); - - $response - ->assertSessionHasErrors('password') - ->assertRedirect(route('profile.edit')); - - expect($user->fresh())->not->toBeNull(); -}); diff --git a/tests/Feature/Settings/SecurityTest.php b/tests/Feature/Settings/SecurityTest.php deleted file mode 100644 index 401bbe2..0000000 --- a/tests/Feature/Settings/SecurityTest.php +++ /dev/null @@ -1,114 +0,0 @@ -skipUnlessFortifyHas(Features::twoFactorAuthentication()); - - Features::twoFactorAuthentication([ - 'confirm' => true, - 'confirmPassword' => true, - ]); - - $user = User::factory()->create(); - - $this->actingAs($user) - ->withSession(['auth.password_confirmed_at' => time()]) - ->get(route('security.edit')) - ->assertInertia(fn (Assert $page) => $page - ->component('settings/security') - ->where('canManageTwoFactor', true) - ->where('twoFactorEnabled', false), - ); -}); - -test('security page requires password confirmation when enabled', function () { - $this->skipUnlessFortifyHas(Features::twoFactorAuthentication()); - - $user = User::factory()->create(); - - Features::twoFactorAuthentication([ - 'confirm' => true, - 'confirmPassword' => true, - ]); - - $response = $this->actingAs($user) - ->get(route('security.edit')); - - $response->assertRedirect(route('password.confirm')); -}); - -test('security page does not require password confirmation when disabled', function () { - $this->skipUnlessFortifyHas(Features::twoFactorAuthentication()); - - $user = User::factory()->create(); - - Features::twoFactorAuthentication([ - 'confirm' => true, - 'confirmPassword' => false, - ]); - - $this->actingAs($user) - ->get(route('security.edit')) - ->assertOk() - ->assertInertia(fn (Assert $page) => $page - ->component('settings/security'), - ); -}); - -test('security page renders without two factor when feature is disabled', function () { - $this->skipUnlessFortifyHas(Features::twoFactorAuthentication()); - - config(['fortify.features' => []]); - - $user = User::factory()->create(); - - $this->actingAs($user) - ->get(route('security.edit')) - ->assertOk() - ->assertInertia(fn (Assert $page) => $page - ->component('settings/security') - ->where('canManageTwoFactor', false) - ->missing('twoFactorEnabled') - ->missing('requiresConfirmation'), - ); -}); - -test('password can be updated', function () { - $user = User::factory()->create(); - - $response = $this - ->actingAs($user) - ->from(route('security.edit')) - ->put(route('user-password.update'), [ - 'current_password' => 'password', - 'password' => 'new-password', - 'password_confirmation' => 'new-password', - ]); - - $response - ->assertSessionHasNoErrors() - ->assertRedirect(route('security.edit')); - - expect(Hash::check('new-password', $user->refresh()->password))->toBeTrue(); -}); - -test('correct password must be provided to update password', function () { - $user = User::factory()->create(); - - $response = $this - ->actingAs($user) - ->from(route('security.edit')) - ->put(route('user-password.update'), [ - 'current_password' => 'wrong-password', - 'password' => 'new-password', - 'password_confirmation' => 'new-password', - ]); - - $response - ->assertSessionHasErrors('current_password') - ->assertRedirect(route('security.edit')); -});