<?php

namespace Tests\Unit\Services\Roles;

use App\Models\Permission;
use App\Services\Roles\PermissionCrudService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class PermissionCrudServiceTest extends TestCase
{
    use RefreshDatabase;

    public function test_create_and_update_permission(): void
    {
        $service = new PermissionCrudService();
        $permission = $service->create([
            'name' => 'manage_roles',
            'description' => 'Manage roles',
        ]);

        $this->assertInstanceOf(Permission::class, $permission);
        $this->assertDatabaseHas('permissions', ['name' => 'manage_roles']);

        $service->update($permission, ['description' => 'Updated']);
        $this->assertDatabaseHas('permissions', ['id' => $permission->id, 'description' => 'Updated']);
    }
}
