aboutsummaryrefslogtreecommitdiffstats
path: root/source/tests/Feature/LogTestApi.php
blob: 809828853fadc5a6ae00f07767daaf98ce03f775 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php

namespace Tests\Feature;

use App\Models\Admin;
use App\Models\Company;
use App\Models\Log;
use App\Models\Student;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Sanctum\Sanctum;
use Tests\TestCase;

class LogTestApi extends TestCase
{
    use RefreshDatabase;

    public function test_admin_can_view_all_logs()
    {
        $admin = Admin::factory()->create();
        Log::factory()->count(5)->create();

        Sanctum::actingAs($admin, ['admin']);

        $response = $this->getJson('/api/logs');
        $response->assertStatus(200);
        $response->assertJsonStructure(['data']);
    }

    public function test_student_cannot_view_logs()
    {
        $student = Student::factory()->create();
        Sanctum::actingAs($student, ['student']);

        $response = $this->getJson('/api/logs');
        $response->assertStatus(403);
    }

    public function test_company_cannot_view_logs()
    {
        $company = Company::factory()->create();
        Sanctum::actingAs($company, ['company']);

        $response = $this->getJson('/api/logs');
        $response->assertStatus(403);
    }

    public function test_unauthenticated_user_cannot_view_logs()
    {
        $response = $this->getJson('/api/logs');
        $response->assertStatus(401);
    }
}