ReportControllerTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace Tests\Feature;
  3. use App\Models\Role;
  4. use App\Models\User;
  5. use Illuminate\Foundation\Testing\RefreshDatabase;
  6. use Tests\TestCase;
  7. class ReportControllerTest extends TestCase
  8. {
  9. use RefreshDatabase;
  10. protected bool $seed = true;
  11. protected User $adminUser;
  12. protected User $managerUser;
  13. protected User $brigadierUser;
  14. protected function setUp(): void
  15. {
  16. parent::setUp();
  17. $this->adminUser = User::factory()->create(['role' => Role::ADMIN]);
  18. $this->managerUser = User::factory()->create(['role' => Role::MANAGER]);
  19. $this->brigadierUser = User::factory()->create(['role' => Role::BRIGADIER]);
  20. }
  21. public function test_guest_cannot_access_reports_index(): void
  22. {
  23. $response = $this->get(route('reports.index'));
  24. $response->assertRedirect(route('login'));
  25. }
  26. public function test_brigadier_cannot_access_reports(): void
  27. {
  28. $response = $this->actingAs($this->brigadierUser)->get(route('reports.index'));
  29. $response->assertStatus(403);
  30. }
  31. public function test_admin_can_access_reports_index(): void
  32. {
  33. $response = $this->actingAs($this->adminUser)->get(route('reports.index'));
  34. $response->assertStatus(200);
  35. $response->assertViewIs('reports.index');
  36. }
  37. public function test_manager_can_access_reports_index(): void
  38. {
  39. $response = $this->actingAs($this->managerUser)->get(route('reports.index'));
  40. $response->assertStatus(200);
  41. $response->assertViewIs('reports.index');
  42. }
  43. public function test_reports_index_contains_required_view_data(): void
  44. {
  45. $response = $this->actingAs($this->adminUser)->get(route('reports.index'));
  46. $response->assertViewHas('totalOrders');
  47. $response->assertViewHas('totalMafs');
  48. $response->assertViewHas('managers');
  49. }
  50. public function test_reports_index_has_done_orders_count(): void
  51. {
  52. $response = $this->actingAs($this->adminUser)->get(route('reports.index'));
  53. $response->assertViewHas('doneOrders', fn($v) => $v >= 0);
  54. }
  55. public function test_reports_index_has_mount_orders_count(): void
  56. {
  57. $response = $this->actingAs($this->adminUser)->get(route('reports.index'));
  58. $response->assertViewHas('mountOrders', fn($v) => $v >= 0);
  59. }
  60. public function test_reports_index_has_reclamations_data(): void
  61. {
  62. $response = $this->actingAs($this->adminUser)->get(route('reports.index'));
  63. $response->assertViewHas('totalReclamations');
  64. $response->assertViewHas('reclamationStatuses');
  65. }
  66. public function test_reports_index_has_by_district_data(): void
  67. {
  68. $response = $this->actingAs($this->adminUser)->get(route('reports.index'));
  69. $response->assertViewHas('byDistrict', fn($v) => is_array($v));
  70. }
  71. public function test_reports_index_has_total_sum(): void
  72. {
  73. $response = $this->actingAs($this->adminUser)->get(route('reports.index'));
  74. $response->assertViewHas('totalSum');
  75. $response->assertViewHas('totalDoneSum');
  76. }
  77. }