I am a totally Laravel Dusk noob, started using it recently. Here is my dusk test method -
public function test_show_new_customer(): void
{
$this->login()->use_application(6);
$this->browse(function (Browser $browser) {
$browser->loginAs($this->user)
->visit(new NewCustomerPage())
->assertTitle('New Customer');
});
}
But, while executing this test I am getting a 401 error.
Here is my middleware where it throws an error -
public function handle(Request $request, Closure $next): Response
{
$has_app_access = User::hasAppAccess(session('business.id'));
if (!$has_app_access) {
abort(401);
}
return $next($request);
}
Error is given due to there being no session found for business id, hence it validates that there is no application access for the logged-in user. When I dump dd(session('business.id')) gives me a null.
I want to set a browser session before visiting a page. Is this possible in Laravel Dusk?