<?php

use App\Enums\UserGroup;
use App\Models\User;

test('user factory creates user with default User group', function () {
    $user = User::factory()->create();

    expect($user->group)->toBeInstanceOf(UserGroup::class)
        ->and($user->group->is(UserGroup::User))->toBeTrue()
        ->and($user->group->value)->toBe('user');
});

test('user factory superadmin state assigns Superadmin group', function () {
    $user = User::factory()->superadmin()->create();

    expect($user->group->is(UserGroup::Superadmin))->toBeTrue()
        ->and($user->group->value)->toBe('superadmin');
});

test('user factory admin state assigns Admin group', function () {
    $user = User::factory()->admin()->create();

    expect($user->group->is(UserGroup::Admin))->toBeTrue()
        ->and($user->group->value)->toBe('admin');
});

test('group is persisted and retrieved correctly from database', function () {
    $user = User::factory()->admin()->create();
    $user->refresh();

    expect($user->group->is(UserGroup::Admin))->toBeTrue();
});
