<?php

use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;

uses(RefreshDatabase::class);

describe('User Model', function () {
    it('can create a user', function () {
        $user = User::factory()->create([
            'name' => 'Test User',
            'email' => 'test@example.com',
        ]);

        expect($user->name)->toBe('Test User')
            ->and($user->email)->toBe('test@example.com')
            ->and($user->exists)->toBeTrue();
    });

    it('has guarded attributes', function () {
        $guarded = ['id'];

        expect(User::make()->getGuarded())->toEqual($guarded);
    });

    it('has hidden attributes', function () {
        $hidden = ['password', 'remember_token'];

        expect(User::make()->getHidden())->toEqual($hidden);
    });

    it('has email verification timestamp', function () {
        $user = User::factory()->create();

        expect($user->getCasts())->toHaveKey('email_verified_at');
    });

    it('can verify email', function () {
        $user = User::factory()->create(['email_verified_at' => null]);

        expect($user->email_verified_at)->toBeNull();

        $user->markEmailAsVerified();

        expect($user->email_verified_at)->not()->toBeNull();
    });
});
