Skip to content

Commit

Permalink
Fix tests and dispatch Verified event on manual email verification
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurpar06 committed Oct 16, 2023
1 parent 36ed8d5 commit f8bd633
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion app/Http/Controllers/Admin/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use App\Services\UserService;
use App\Support\Timezonelist;
use App\Support\Utils;
use Illuminate\Auth\Events\Verified;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
Expand Down Expand Up @@ -337,7 +338,9 @@ public function verify_email(int $id, Request $request): RedirectResponse
return back();
}

$user->markEmailAsVerified();
if ($user->markEmailAsVerified()) {
event(new Verified($user));
}

Flash::success('User email verified successfully');
return back();
Expand Down
6 changes: 5 additions & 1 deletion tests/RegistrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Models\User;
use App\Notifications\Messages\AdminUserRegistered;
use App\Services\UserService;
use Illuminate\Auth\Events\Verified;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Notification;

Expand All @@ -29,11 +30,14 @@ public function testRegistration()

$attrs = User::factory()->make()->makeVisible(['api_key', 'name', 'email'])->toArray();
$attrs['password'] = Hash::make('secret');
$attrs['flights'] = 0;
$user = $userSvc->createUser($attrs);

$this->assertEquals(UserState::ACTIVE, $user->state);

$user->markEmailAsVerified();
if ($user->markEmailAsVerified()) {
event(new Verified($user));
}

Notification::assertSentTo([$admin], AdminUserRegistered::class);
Notification::assertNotSentTo([$user], AdminUserRegistered::class);
Expand Down

0 comments on commit f8bd633

Please sign in to comment.