<?php

namespace Tests\Feature\V3\AzmayeshType;

use App\Models\AzmayeshType;
use App\Models\Permission;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

class ListTest extends TestCase
{
    use RefreshDatabase;
    /**
     * A basic feature test example.
     */
    public function test_user_should_have_azmayesh_type_management_permission(): void
    {
        $user = User::factory()->create();

        $response = $this->actingAs($user)->getJson(route('v3.azmayesh_types.list'));

        $response->assertForbidden();
    }

    public function test_azmayesh_type_list_returned_successfully(): void
    {
        AzmayeshType::factory(5)->create();

        $user = User::factory()
            ->has(Permission::factory([
                'name' => 'azmayesh-type-management'
            ]))
            ->create();

        $response = $this->actingAs($user)->getJson(route('v3.azmayesh_types.list'));

        $response->assertOk();

        $response->assertJsonStructure([
            'data' => [
                '*' => [
                    'name',
                ],
            ]
        ]);
    }
}
