<?php

namespace Tests\Feature;

use App\Models\User;
use App\Models\WebauthnCredential;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class WebauthnCredentialTest extends TestCase
{
    use RefreshDatabase;

    public function test_user_has_webauthn_credentials(): void
    {
        $user = User::factory()->create();
        $this->assertFalse($user->hasWebauthnCredentials());

        WebauthnCredential::create([
            'user_id' => $user->id, 'name' => 'YubiKey 5C', 'credential_id' => 'abc',
            'public_key' => '{}', 'sign_count' => 0,
        ]);

        $this->assertTrue($user->fresh()->hasWebauthnCredentials());
        $this->assertCount(1, $user->fresh()->webauthnCredentials);
    }
}
