<?php

use App\Enums\RoleSlug;
use App\Models\User;
use Database\Seeders\AdminUserSeeder;
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
use Illuminate\Support\Facades\Hash;

uses(LazilyRefreshDatabase::class);

it('creates the development admin user once', function () {
    $this->seed(AdminUserSeeder::class);
    $this->seed(AdminUserSeeder::class);

    $admins = User::query()->where('email', 'admin@royaldevelopers.test')->get();

    expect($admins)->toHaveCount(1);

    $admin = $admins->first();

    expect($admin)->not->toBeNull()
        ->and($admin->name)->toBe('Royal Admin')
        ->and($admin->role->slug)->toBe(RoleSlug::Admin)
        ->and(Hash::check('password', $admin->password))->toBeTrue();
});
