<?php

namespace Tests\Unit\Modules\Segments\Services;

use App\Classes\Modules\Segments\DataTransferObjects\SegmentObject;
use App\Classes\Modules\Segments\Services\CreatesSegment;
use App\Models\Segment;
use App\Classes\ValueObjects\Constants\SegmentConstants;
use PHPUnit\Framework\Attributes\Group;
use Tests\TestCase;

#[Group('unit')]
#[Group('segments')]
#[Group('services')]
#[Group('ok_to_run')]
class CreatesSegmentTest extends TestCase
{
    // use DatabaseTransactions;

    /**
     * Test it can create a segment.
     *
     * @return void
     * @throws \App\Classes\Exceptions\MalformedRequestException
     */
    public function test_it_can_create_a_segment()
    {
        // A R R A N G E
        $name = 'test_it_can_create_a_segment';
        $type = SegmentConstants::STANDARD_SEGMENT;
        $object = new SegmentObject($name, $type);
        $service = new CreatesSegment();

        // A C T
        $result = $service->execute($object);

        // A S S E R T
        $this->assertInstanceOf(Segment::class, $result);
        $this->assertEquals($name, $result->name);
        $this->assertEquals($type, $result->type);

        $this->assertDatabaseHas('segments', [
            'id' => $result->id,
            'name' => $name,
            'type' => $type,
        ]);
    }
}
