<?php

namespace Tests\Feature;

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

class UserRoleAssignmentTest extends TestCase
{
    use RefreshDatabase;

    /**
     * TC-2.2: Assign role to user
     * Module: Role Management
     * Preconditions: Existing role & user
     * Test Steps:
     *   1. Edit user
     *   2. Select role
     *   3. Save
     * Expected Result: User assigned correct role
     */
    public function test_assign_role_to_user()
    {
        // Preconditions: create user and role
        $user = User::factory()->create();
        $role = Role::create(['name' => 'Editor']);

        // Step 1: Edit user (simulate by assigning role)
        $user->assignRole($role);

        // Step 2: Select role (already done above)
        // Step 3: Save (already done above)

        // Expected Result: User assigned correct role
        $this->assertTrue($user->hasRole('Editor'));
    }
}
