<?php

namespace Tests\Unit\Services\BroadcastEmail;

use App\Services\BroadcastEmail\BroadcastEmailComposerService;
use Tests\TestCase;

class BroadcastEmailComposerServiceTest extends TestCase
{
    public function test_sanitize_removes_script_and_events(): void
    {
        $service = new BroadcastEmailComposerService();
        $html = '<p onclick="alert(1)">Hi</p><script>alert(2)</script>';

        $clean = $service->sanitizeHtml($html);

        $this->assertStringNotContainsString('script', $clean);
        $this->assertStringNotContainsString('onclick', $clean);
    }

    public function test_compose_replaces_name_when_personalized(): void
    {
        $service = new BroadcastEmailComposerService();
        $html = '<p>Hello {{name}}</p>';

        $rendered = $service->compose(false, 'Subject', $html, 'Parent', '', '', '', true);

        $this->assertSame('<p>Hello Parent</p>', $rendered);
    }
}
