<?php

namespace Tests\Unit\Modules\Segments\Services;

use App\Classes\Modules\Segments\Services\DeletesSegment;
use App\Models\Segment;
use PHPUnit\Framework\Attributes\Group;
use Tests\TestCase;

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

    /**
     * Test it can delete a segment.
     *
     * @return void
     * @throws \App\Classes\Exceptions\MalformedRequestException
     */
    public function test_it_can_delete_a_segment()
    {
        // A R R A N G E
        $segment = new Segment();
        $segment->name = 'test_it_can_delete_a_segment';
        $segment->save();

        $service = new DeletesSegment();

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

        // A S S E R T
        $this->assertIsArray($result);

        // Since Segment uses SoftDeletes, check if it's still in DB but trashed
        $this->assertSoftDeleted('segments', [
            'id' => $segment->id,
        ]);
    }
}
