Files
shopit-back/tests/Unit/Ticket/ValidityTimeTest.php
ncoronel 573d4fe5e6 Refactor ticket validity handling and improve tests
- Updated tests for Accommodation, Entry, Food, Merchandise, and Sale controllers to use soft deletes for variants and ensure proper inventory counts.
- Enhanced ticket generation logic to resolve validity from soft-deleted catalog sources.
- Introduced a new TicketValidityResolver service to manage ticket validity based on event dates and variant definitions.
- Removed unnecessary database assertions and improved the clarity of validity checks in tests.
- Added comprehensive tests for the new TicketValidityResolver service, ensuring correct handling of event dates and multi-select options.
- Cleaned up unused code and assertions in existing tests for better maintainability.
2026-08-14 09:00:51 -03:00

64 lines
2.2 KiB
PHP

<?php
namespace Tests\Unit\Ticket;
use App\Domains\Catalog\Models\AttributeOption;
use App\Domains\Ticket\Enums\ValidityTimeType;
use App\Domains\Ticket\Models\ValidityTime;
use Illuminate\Support\Carbon;
use Tests\TestCase;
class ValidityTimeTest extends TestCase
{
public function test_it_casts_its_type_dates_and_flags(): void
{
$validityTime = new ValidityTime;
$validityTime->setRawAttributes([
'type' => ValidityTimeType::FixedWindow->value,
'fixed_starts_at' => '2026-08-20 10:00:00',
'fixed_expires_at' => '2026-08-21 02:00:00',
]);
$this->assertSame(ValidityTimeType::FixedWindow, $validityTime->type);
$this->assertInstanceOf(Carbon::class, $validityTime->fixed_starts_at);
$this->assertInstanceOf(Carbon::class, $validityTime->fixed_expires_at);
$this->assertInstanceOf(AttributeOption::class, $validityTime->attributeOptions()->getRelated());
}
public function test_it_exposes_supported_type_values(): void
{
$this->assertSame([
'time_window',
'fixed_window',
], ValidityTimeType::values());
}
public function test_fixed_window_is_valid_between_its_limits(): void
{
$validityTime = new ValidityTime([
'type' => ValidityTimeType::FixedWindow,
'fixed_starts_at' => '2026-08-20 10:00:00',
'fixed_expires_at' => '2026-08-20 12:00:00',
]);
$this->assertTrue($validityTime->isValid(at: Carbon::parse('2026-08-20 10:00:00')));
$this->assertTrue($validityTime->isValid(at: Carbon::parse('2026-08-20 11:00:00')));
$this->assertFalse($validityTime->isValid(at: Carbon::parse('2026-08-20 12:00:00')));
}
public function test_time_window_is_valid_between_its_limits(): void
{
$validityTime = new ValidityTime([
'type' => ValidityTimeType::TimeWindow,
'start_time' => '11:00:00',
'end_time' => '14:00:00',
]);
$this->assertTrue($validityTime->isValid(
Carbon::parse('2026-08-20 12:00:00'),
));
$this->assertFalse($validityTime->isValid(
Carbon::parse('2026-08-20 14:00:00'),
));
}
}