WarehouseHeadOrderVisibilityTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace Tests\Feature;
  3. use App\Models\Order;
  4. use App\Models\OrderView;
  5. use App\Models\Role;
  6. use App\Models\User;
  7. use Database\Seeders\OrderStatusSeeder;
  8. use Illuminate\Foundation\Testing\RefreshDatabase;
  9. use Tests\TestCase;
  10. class WarehouseHeadOrderVisibilityTest extends TestCase
  11. {
  12. use RefreshDatabase;
  13. public function setUp(): void
  14. {
  15. parent::setUp();
  16. $this->seed(OrderStatusSeeder::class);
  17. }
  18. public function test_warehouse_head_sees_only_orders_with_brigadier_and_installation_date()
  19. {
  20. // 1. Create a user with the "warehouse_head" role.
  21. $warehouseHead = User::factory()->create(['role' => Role::WAREHOUSE_HEAD]);
  22. $brigadier = User::factory()->create(['role' => Role::BRIGADIER]);
  23. // 2. Create orders
  24. $orderVisible = Order::factory()->create([
  25. 'brigadier_id' => $brigadier->id,
  26. 'installation_date' => now(),
  27. ]);
  28. $orderNotVisible1 = Order::factory()->create([
  29. 'brigadier_id' => $brigadier->id,
  30. 'installation_date' => null,
  31. ]);
  32. $orderNotVisible2 = Order::factory()->create([
  33. 'brigadier_id' => null,
  34. 'installation_date' => now(),
  35. ]);
  36. $orderNotVisible3 = Order::factory()->create([
  37. 'brigadier_id' => null,
  38. 'installation_date' => null,
  39. ]);
  40. // 3. Authenticate as the "warehouse_head" user.
  41. $this->actingAs($warehouseHead);
  42. // 4. Make a request to the `order.index` route.
  43. $response = $this->get(route('order.index'));
  44. // 5. Assert that the response only contains the order that has both a brigadier and an installation date.
  45. $response->assertStatus(200);
  46. $orders = $response->viewData('orders');
  47. $this->assertCount(1, $orders);
  48. $this->assertEquals($orderVisible->id, $orders->first()->id);
  49. }
  50. }