aboutsummaryrefslogtreecommitdiffstats
path: root/source/tests/Feature/DiplomaApiTest.php
blob: d2583f6744a518cdb2d10fe78e41a60574108308 (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
<?php

namespace Tests\Feature;

use App\Models\Diploma;
use Database\Seeders\DiplomaSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class DiplomaApiTest extends TestCase
{
    use RefreshDatabase;

    public function test_index_returns_all_diplomas()
    {
        $this->seed(DiplomaSeeder::class);

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

    public function test_show_returns_single_diploma()
    {
        $this->seed(DiplomaSeeder::class);
        $diploma = Diploma::first();

        $response = $this->getJson("/api/diplomas/{$diploma->id}");

        $response->assertStatus(200)
            ->assertJson([
                'data' => [
                    'id' => $diploma->id,
                    'type' => $diploma->type,
                ]
            ]);
    }

    public function test_show_returns_404_if_diploma_not_found()
    {
        $response = $this->getJson('/api/diplomas/999');

        $response->assertStatus(404);
    }
}