Skip to content

Commit

Permalink
Add Registered event to external auth controller and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaszkadziela committed Jun 21, 2024
1 parent fded1e3 commit 88fb401
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/Http/Controllers/ExternalAuth/ExternalAuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Notifications\AccountCreatedViaProvider;
use App\Providers\RouteServiceProvider;
use App\View\Components\Notification;
use Illuminate\Auth\Events\Registered;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Auth;
Expand Down Expand Up @@ -61,6 +62,8 @@ public function callback(): RedirectResponse
$user->save();

$user->notify(new AccountCreatedViaProvider($this->getProviderName(), $user->email, $password));

event(new Registered($user));
}

Auth::login($user, true);
Expand Down
6 changes: 6 additions & 0 deletions tests/Feature/ExternalAuth/FacebookAuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Models\User;
use App\Notifications\AccountCreatedViaProvider;
use App\Providers\RouteServiceProvider;
use Illuminate\Auth\Events\Registered;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Log\Events\MessageLogged;
use Illuminate\Notifications\Events\NotificationSent;
Expand Down Expand Up @@ -133,6 +134,11 @@ public function test_guest_can_create_account_via_facebook(): void
fn (NotificationSent $event) => $event->notification instanceof AccountCreatedViaProvider,
);

Event::assertDispatched(
Registered::class,
fn (Registered $event) => $event->user->id === $user->id,
);

$this->assertAuthenticatedAs($user);

$response->assertRedirect(RouteServiceProvider::HOME);
Expand Down
6 changes: 6 additions & 0 deletions tests/Feature/ExternalAuth/GoogleAuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Models\User;
use App\Notifications\AccountCreatedViaProvider;
use App\Providers\RouteServiceProvider;
use Illuminate\Auth\Events\Registered;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Log\Events\MessageLogged;
use Illuminate\Notifications\Events\NotificationSent;
Expand Down Expand Up @@ -131,6 +132,11 @@ public function test_guest_can_create_account_via_google(): void
fn (NotificationSent $event) => $event->notification instanceof AccountCreatedViaProvider,
);

Event::assertDispatched(
Registered::class,
fn (Registered $event) => $event->user->id === $user->id,
);

$this->assertAuthenticatedAs($user);

$response->assertRedirect(RouteServiceProvider::HOME);
Expand Down

0 comments on commit 88fb401

Please sign in to comment.