<?php

namespace Tests\Feature\Permission;

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

class SHowTest extends TestCase
{
    use RefreshDatabase, WithFaker;

    public function test_guest_cannot_view_permission(): void
    {
        $permission = Permission::factory()->create();

        $response = $this->getJson(route('permissions.show', [$permission->id]));

        $response->assertUnauthorized();
    }
    public function test_permission_show_returns_correct_structure_and_data(): void
    {
        $user = User::factory()
            ->create();

        $permission = Permission::factory()->create([
            'name' => 'edit-posts',
            'name_fa' => 'ویرایش پست‌ها',
            'guard_name' => 'web',
        ]);

        $response = $this->actingAs($user)->getJson(route('permissions.show', [$permission->id]));

        $response->assertOk()
            ->assertJson([
                'data' => [
                    'id' => $permission->id,
                    'name' => 'edit-posts',
                    'name_fa' => 'ویرایش پست‌ها',
                    'guard_name' => 'web',
                ]
            ]);
    }


}
