How can I write a test for facebook auth in Laravel? I have done all my normal test but when I reach facebook auth section I do not know what is the best or correct way to make a test for it, my code:
class FacebookAuthController extends Controller
{
public function redirect()
{
return Socialite::driver('facebook')->redirect();
}
public function callback()
{
$user = Socialite::driver('facebook')->user();
$user = User::firstOrCreate(
['facebook_id' => $user->id],
[
'name' => $user->name,
'email' => $user->email,
'facebook_id' => $user->id,
]
);
Auth::login($user);
return redirect('/#');
}
}
Routes
Route::get('/auth/redirect', [FacebookAuthController::class, 'redirect'])->name('facebook.redirect');
Route::get('/auth/callback', [FacebookAuthController::class, 'callback'])->name('facebook.callback');
I always mock those kind of tests. Before I've had tests that tested the auth for real. But I've found that I will get notified by the customer support or some user far before I notice that something is broken with the auth via tests.
To me, it seems that Taylor makes sure Laravel Socialite is already tested, and the same for Facebook.
Ask, does this really need testing if real World works.
Just a thought.
Please sign in or create an account to participate in this conversation.