| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace Tests\Feature;
- use App\Models\Role;
- use App\Models\User;
- use Illuminate\Foundation\Testing\RefreshDatabase;
- use Tests\TestCase;
- class ReportControllerTest extends TestCase
- {
- use RefreshDatabase;
- protected bool $seed = true;
- protected User $adminUser;
- protected User $managerUser;
- protected User $brigadierUser;
- protected function setUp(): void
- {
- parent::setUp();
- $this->adminUser = User::factory()->create(['role' => Role::ADMIN]);
- $this->managerUser = User::factory()->create(['role' => Role::MANAGER]);
- $this->brigadierUser = User::factory()->create(['role' => Role::BRIGADIER]);
- }
- public function test_guest_cannot_access_reports_index(): void
- {
- $response = $this->get(route('reports.index'));
- $response->assertRedirect(route('login'));
- }
- public function test_brigadier_cannot_access_reports(): void
- {
- $response = $this->actingAs($this->brigadierUser)->get(route('reports.index'));
- $response->assertStatus(403);
- }
- public function test_admin_can_access_reports_index(): void
- {
- $response = $this->actingAs($this->adminUser)->get(route('reports.index'));
- $response->assertStatus(200);
- $response->assertViewIs('reports.index');
- }
- public function test_manager_can_access_reports_index(): void
- {
- $response = $this->actingAs($this->managerUser)->get(route('reports.index'));
- $response->assertStatus(200);
- $response->assertViewIs('reports.index');
- }
- public function test_reports_index_contains_required_view_data(): void
- {
- $response = $this->actingAs($this->adminUser)->get(route('reports.index'));
- $response->assertViewHas('totalOrders');
- $response->assertViewHas('totalMafs');
- $response->assertViewHas('managers');
- }
- public function test_reports_index_has_done_orders_count(): void
- {
- $response = $this->actingAs($this->adminUser)->get(route('reports.index'));
- $response->assertViewHas('doneOrders', fn($v) => $v >= 0);
- }
- public function test_reports_index_has_mount_orders_count(): void
- {
- $response = $this->actingAs($this->adminUser)->get(route('reports.index'));
- $response->assertViewHas('mountOrders', fn($v) => $v >= 0);
- }
- public function test_reports_index_has_reclamations_data(): void
- {
- $response = $this->actingAs($this->adminUser)->get(route('reports.index'));
- $response->assertViewHas('totalReclamations');
- $response->assertViewHas('reclamationStatuses');
- }
- public function test_reports_index_has_by_district_data(): void
- {
- $response = $this->actingAs($this->adminUser)->get(route('reports.index'));
- $response->assertViewHas('byDistrict', fn($v) => is_array($v));
- }
- public function test_reports_index_has_total_sum(): void
- {
- $response = $this->actingAs($this->adminUser)->get(route('reports.index'));
- $response->assertViewHas('totalSum');
- $response->assertViewHas('totalDoneSum');
- }
- }
|