feat(event): add EventDateInfoFormatter to format event date messages and implement related tests
This commit is contained in:
51
tests/Unit/Event/EventDateInfoFormatterTest.php
Normal file
51
tests/Unit/Event/EventDateInfoFormatterTest.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Event;
|
||||
|
||||
use App\Domains\Event\Enums\EventDateChangeType;
|
||||
use App\Domains\Event\Models\EventDate;
|
||||
use App\Domains\Event\Models\EventDateChange;
|
||||
use App\Domains\Event\Services\EventDateInfoFormatter;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EventDateInfoFormatterTest extends TestCase
|
||||
{
|
||||
public function test_it_returns_null_for_a_date_without_changes(): void
|
||||
{
|
||||
$date = new EventDate;
|
||||
$date->id = 10;
|
||||
|
||||
$this->assertNull((new EventDateInfoFormatter)->format($date, collect()));
|
||||
}
|
||||
|
||||
public function test_it_formats_cancellation_and_source_dates_for_a_reschedule_destination(): void
|
||||
{
|
||||
$date = new EventDate;
|
||||
$date->id = 20;
|
||||
$date->suspended_at = Carbon::parse('2026-09-15');
|
||||
|
||||
$changes = collect([
|
||||
$this->reschedule(1, 20, '2026-10-09'),
|
||||
$this->reschedule(2, 20, '2026-10-10'),
|
||||
]);
|
||||
|
||||
$this->assertSame(
|
||||
'Esta fecha fue cancelada. 09/10/2026 y 10/10/2026 se reprogramaron para este día.',
|
||||
(new EventDateInfoFormatter)->format($date, $changes),
|
||||
);
|
||||
}
|
||||
|
||||
private function reschedule(int $sourceId, int $destinationId, string $previousDate): EventDateChange
|
||||
{
|
||||
$change = new EventDateChange;
|
||||
$change->setRawAttributes([
|
||||
'change_type' => EventDateChangeType::Rescheduled->value,
|
||||
'source_event_date_id' => $sourceId,
|
||||
'destination_event_date_id' => $destinationId,
|
||||
'previous_date' => $previousDate,
|
||||
]);
|
||||
|
||||
return $change;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user