<?php

namespace Tests\Feature;

use App\Models\User;
use App\Notifications\VerifyEmailNotification;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Support\Facades\Notification;
use Tests\TestCase;

class VerifyEmailNotificationTest extends TestCase
{
    use RefreshDatabase;

    public function test_user_sends_custom_verify_email_notification(): void
    {
        Notification::fake();

        $user = User::factory()->create([
            'email_verified_at' => null,
        ]);

        $user->sendEmailVerificationNotification();

        Notification::assertSentTo($user, VerifyEmailNotification::class);
    }

    public function test_verify_email_notification_uses_custom_view(): void
    {
        $user = User::factory()->create([
            'email_verified_at' => null,
        ]);

        $notification = new VerifyEmailNotification;
        $mailMessage = $notification->toMail($user);

        $this->assertInstanceOf(MailMessage::class, $mailMessage);
        $this->assertSame('emails.verify-email', $mailMessage->view);
        $this->assertArrayHasKey('verificationUrl', $mailMessage->viewData);
        $this->assertArrayHasKey('user', $mailMessage->viewData);
        $this->assertSame($user->getKey(), $mailMessage->viewData['user']->getKey());
    }
}
