<?php

namespace Tests\Unit\Support;

use App\Support\CatalogGoogleConversion;
use Tests\TestCase;

class CatalogGoogleConversionTest extends TestCase
{
    public function test_it_builds_a_conversion_from_a_saved_send_to_value(): void
    {
        $conversion = CatalogGoogleConversion::fromSendTo('AW-16990837573/i9NRCNzf3PkcEMW27qU_');

        $this->assertSame('AW-16990837573', $conversion?->accountId);
        $this->assertSame('AW-16990837573/i9NRCNzf3PkcEMW27qU_', $conversion?->sendTo);
        $this->assertSame(['send_to' => 'AW-16990837573/i9NRCNzf3PkcEMW27qU_'], $conversion?->payload);
    }

    public function test_it_returns_null_when_no_send_to_is_saved(): void
    {
        $this->assertNull(CatalogGoogleConversion::fromSendTo(null));
        $this->assertNull(CatalogGoogleConversion::fromSendTo(''));
    }

    public function test_it_returns_null_for_an_invalid_send_to_value(): void
    {
        $this->assertNull(CatalogGoogleConversion::fromSendTo("AW-1';alert(1)//"));
    }
}
