From 21a0522c750109e5e915b0a05f9dcae6dae0523d Mon Sep 17 00:00:00 2001 From: Steven Fox <62109327+steven-fox@users.noreply.github.com> Date: Fri, 23 May 2025 14:23:41 -0400 Subject: [PATCH] validate email before create in MobilePricing --- app/Livewire/MobilePricing.php | 5 +++++ tests/Feature/MobilePricingTest.php | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/app/Livewire/MobilePricing.php b/app/Livewire/MobilePricing.php index 4712b216..b90c47e1 100644 --- a/app/Livewire/MobilePricing.php +++ b/app/Livewire/MobilePricing.php @@ -7,6 +7,7 @@ use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Log; +use Illuminate\Support\Facades\Validator; use Illuminate\Support\Str; use Livewire\Component; @@ -71,6 +72,10 @@ public function createCheckoutSession(string $plan, ?User $user = null) private function findOrCreateUser(string $email): User { + Validator::validate(['email' => $email], [ + 'email' => 'required|email|max:255', + ]); + return User::firstOrCreate([ 'email' => $email, ], [ diff --git a/tests/Feature/MobilePricingTest.php b/tests/Feature/MobilePricingTest.php index 5deba73e..ca11e7b3 100644 --- a/tests/Feature/MobilePricingTest.php +++ b/tests/Feature/MobilePricingTest.php @@ -60,4 +60,12 @@ public function authenticated_users_do_not_see_purchase_modal_component() Livewire::test(MobilePricing::class) ->assertDontSeeLivewire('purchase-modal'); } + + #[Test] + public function it_validates_email_before_creating_user() + { + Livewire::test(MobilePricing::class) + ->call('handlePurchaseRequest', ['email' => 'invalid-email']) + ->assertHasErrors('email'); + } }