aboutsummaryrefslogtreecommitdiffstats
path: root/source/tests/Feature/LogApiTest.php
blob: 6ce1f0dd628c304fddd39ad42352c683e16db361 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?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 LogApiTest extends TestCase
{
    use RefreshDatabase;

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

        Sanctum::actingAs($admin, ['admin']);
        $response = $this->getJson('/api/admin/logs');

        $response->assertStatus(200)
            ->assertJsonStructure(['data']);
    }

    public function test_get_student_logs()
    {
        $admin = Admin::factory()->create();
        $student = Student::factory()->create();

        Log::factory()->create([
            'actor' => 'Student',
            'actor_id' => $student->id,
        ]);

        Sanctum::actingAs($admin, ['admin']);
        $response = $this->getJson("/api/admin/logs/students/{$student->id}");

        $response->assertStatus(200)
            ->assertJsonStructure(['data']);
    }

    public function test_get_company_logs()
    {
        $admin = Admin::factory()->create();
        $company = Company::factory()->create();

        Log::factory()->create([
            'actor' => 'Company',
            'actor_id' => $company->id,
        ]);

        Sanctum::actingAs($admin, ['admin']);
        $response = $this->getJson("/api/admin/logs/companies/{$company->id}");

        $response->assertStatus(200)
            ->assertJsonStructure(['data']);
    }

    public function test_get_admin_logs()
    {
        $admin = Admin::factory()->create();

        Log::factory()->create([
            'actor' => 'Admin',
            'actor_id' => $admin->id,
        ]);

        Sanctum::actingAs($admin, ['admin']);
        $response = $this->getJson("/api/admin/logs/admins/{$admin->id}");

        $response->assertStatus(200)
            ->assertJsonStructure(['data']);
    }
}