<?php

namespace Tests\Unit\Services\Roles;

use App\Models\Role;
use App\Services\Roles\RoleCrudService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class RoleCrudServiceTest extends TestCase
{
    use RefreshDatabase;

    public function test_create_and_update_role(): void
    {
        $service = new RoleCrudService();
        $role = $service->create([
            'name' => 'admin',
            'slug' => 'admin',
            'description' => 'Admin',
            'dashboard_route' => 'administrator/administratordashboard',
            'priority' => 1,
            'is_active' => 1,
        ]);

        $this->assertInstanceOf(Role::class, $role);
        $this->assertDatabaseHas('roles', ['name' => 'admin']);

        $service->update($role, ['description' => 'updated']);
        $this->assertDatabaseHas('roles', ['id' => $role->id, 'description' => 'updated']);
    }
}
