seed(OrderStatusSeeder::class); } public function test_warehouse_head_sees_only_orders_with_brigadier_and_installation_date() { // 1. Create a user with the "warehouse_head" role. $warehouseHead = User::factory()->create(['role' => Role::WAREHOUSE_HEAD]); $brigadier = User::factory()->create(['role' => Role::BRIGADIER]); // 2. Create orders $orderVisible = Order::factory()->create([ 'brigadier_id' => $brigadier->id, 'installation_date' => now(), ]); $orderNotVisible1 = Order::factory()->create([ 'brigadier_id' => $brigadier->id, 'installation_date' => null, ]); $orderNotVisible2 = Order::factory()->create([ 'brigadier_id' => null, 'installation_date' => now(), ]); $orderNotVisible3 = Order::factory()->create([ 'brigadier_id' => null, 'installation_date' => null, ]); // 3. Authenticate as the "warehouse_head" user. $this->actingAs($warehouseHead); // 4. Make a request to the `order.index` route. $response = $this->get(route('order.index')); // 5. Assert that the response only contains the order that has both a brigadier and an installation date. $response->assertStatus(200); $orders = $response->viewData('orders'); $this->assertCount(1, $orders); $this->assertEquals($orderVisible->id, $orders->first()->id); } }