56 lines
1.9 KiB
PHP
56 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Ticket;
|
|
|
|
use App\Domains\Ticket\Enums\ValidityTimeType;
|
|
use App\Domains\Ticket\Models\ValidityTime;
|
|
use App\Domains\Ticket\Resources\ValidityTimeResource;
|
|
use Illuminate\Support\Carbon;
|
|
use Tests\TestCase;
|
|
|
|
class ValidityTimeResourceTest extends TestCase
|
|
{
|
|
protected function tearDown(): void
|
|
{
|
|
Carbon::setTestNow();
|
|
|
|
parent::tearDown();
|
|
}
|
|
|
|
public function test_time_window_only_contains_non_null_time_fields(): void
|
|
{
|
|
Carbon::setTestNow('2026-08-20 12:00:00');
|
|
$resource = ValidityTimeResource::make(new ValidityTime([
|
|
'type' => ValidityTimeType::TimeWindow,
|
|
'start_time' => '11:00:00',
|
|
'end_time' => null,
|
|
'fixed_starts_at' => '2026-08-20 10:00:00',
|
|
]))->resolve();
|
|
|
|
$this->assertSame('time_window', $resource['type']);
|
|
$this->assertTrue($resource['is_valid']);
|
|
$this->assertSame('11:00:00', $resource['start_time']);
|
|
$this->assertArrayNotHasKey('end_time', $resource);
|
|
$this->assertArrayNotHasKey('fixed_starts_at', $resource);
|
|
$this->assertArrayNotHasKey('fixed_expires_at', $resource);
|
|
}
|
|
|
|
public function test_fixed_window_only_contains_non_null_datetime_fields(): void
|
|
{
|
|
Carbon::setTestNow('2026-08-20 11:00:00');
|
|
$resource = ValidityTimeResource::make(new ValidityTime([
|
|
'type' => ValidityTimeType::FixedWindow,
|
|
'start_time' => '11:00:00',
|
|
'fixed_starts_at' => '2026-08-20 10:00:00',
|
|
'fixed_expires_at' => null,
|
|
]))->resolve();
|
|
|
|
$this->assertSame('fixed_window', $resource['type']);
|
|
$this->assertTrue($resource['is_valid']);
|
|
$this->assertArrayHasKey('fixed_starts_at', $resource);
|
|
$this->assertArrayNotHasKey('fixed_expires_at', $resource);
|
|
$this->assertArrayNotHasKey('start_time', $resource);
|
|
$this->assertArrayNotHasKey('end_time', $resource);
|
|
}
|
|
}
|