i have this test
public function testCanViewMonthlyReport(): void
{
$account = $this->createFakeAccount();
$order = Order::factory()->create([
'account_id' => $account->id,
]);
$salesUser = User::factory()->createOneQuietly(['role_id' => Role::ROLE_USER_SALES]);
$this->actingAs($salesUser)
->get('/report/order-monthly-report/' . $order->id)
->assertForbidden();
}
this is my route
Route::group(['middleware' => ['auth', 'roles'], 'roles' => [Role::ROLE_USER_ADMIN, Role::ROLE_USER_ANALYST]], function () {
Route::get('/report/order-monthly-report/{orderId}', ['as' => 'report.order-monthly-report', 'uses' => 'ReportController@orderMonthlyReport']);
});
As a result, it should return a 403 Forbidden response. But when the test performs a GET request to that endpoint, it unexpectedly returns a 200 OK response instead of the expected 403. This is causing a false positive. What changes do I need to make to my test to fix this? The functionality works as expected when I manually navigate to the route in the browser, so the roles middleware is configured correctly.
I believe the issue is that the middleware isn't being loaded within the testing environment.