From 00586e168fa92762787b741ac673eb3e2da064d8 Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Thu, 30 Apr 2026 09:05:29 +0700 Subject: [PATCH] refactor: remove email verification reset on profile update and add feature tests for profile settings --- .../Settings/ProfileController.php | 4 - tests/Feature/Settings/ProfileTest.php | 116 ++++++++++++++++++ 2 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 tests/Feature/Settings/ProfileTest.php diff --git a/app/Http/Controllers/Settings/ProfileController.php b/app/Http/Controllers/Settings/ProfileController.php index ad80162..072dba7 100644 --- a/app/Http/Controllers/Settings/ProfileController.php +++ b/app/Http/Controllers/Settings/ProfileController.php @@ -40,10 +40,6 @@ public function update(ProfileUpdateRequest $request): RedirectResponse 'email' => $validated['email'], ]); - if ($user->isDirty('email')) { - $user->email_verified_at = null; - } - $user->save(); $user->profile()->update([ diff --git a/tests/Feature/Settings/ProfileTest.php b/tests/Feature/Settings/ProfileTest.php new file mode 100644 index 0000000..8d3f715 --- /dev/null +++ b/tests/Feature/Settings/ProfileTest.php @@ -0,0 +1,116 @@ +assertRedirect(route('login')); + get(route('security.edit'))->assertRedirect(route('login')); + get(route('appearance.edit'))->assertRedirect(route('login')); + }); +}); + +describe('Profile Settings Module - Actions', function () { + beforeEach(function () { + $this->user = User::factory()->create(); + actingAs($this->user); + }); + + it('can access profile edit page', function () { + get(route('profile.edit')) + ->assertOk() + ->assertInertia(fn ($page) => $page + ->component('settings/profile') + ); + }); + + it('can update profile information', function () { + $newData = [ + 'username' => 'newusername', + 'email' => 'newemail@example.com', + 'nik' => '1234567890123456', + 'full_name' => 'New Full Name', + 'phone_number' => '081234567890', + 'address' => 'New Address', + 'birth_place' => 'New City', + 'birth_date' => '1990-01-01', + ]; + + patch(route('profile.update'), $newData) + ->assertRedirect(route('profile.edit')) + ->assertSessionHas('success'); + + assertDatabaseHas('users', [ + 'id' => $this->user->id, + 'username' => 'newusername', + 'email' => 'newemail@example.com', + ]); + + assertDatabaseHas('user_profiles', [ + 'user_id' => $this->user->id, + 'nik' => '1234567890123456', + 'full_name' => 'New Full Name', + ]); + }); + + it('can delete profile', function () { + delete(route('profile.destroy'), [ + 'password' => 'password', + ])->assertRedirect('/'); + + assertGuest(); + assertSoftDeleted('users', ['id' => $this->user->id]); + }); + + it('can access security edit page', function () { + get(route('security.edit')) + ->assertOk() + ->assertInertia(fn ($page) => $page + ->component('settings/security') + ); + }); + + it('can update password', function () { + $response = put(route('user-password.update'), [ + 'current_password' => 'password', // Default factory password + 'password' => 'newpassword123', + 'password_confirmation' => 'newpassword123', + ]); + + $response->assertRedirect(); + + expect(Hash::check('newpassword123', $this->user->fresh()->password))->toBeTrue(); + }); + + it('validates password update', function () { + put(route('user-password.update'), [ + 'current_password' => 'wrongpassword', + 'password' => 'newpassword123', + 'password_confirmation' => 'newpassword123', + ])->assertSessionHasErrors(['current_password']); + }); + + it('can access appearance page', function () { + get(route('appearance.edit')) + ->assertOk() + ->assertInertia(fn ($page) => $page + ->component('settings/appearance') + ); + }); +});