102 lines
3.8 KiB
PHP
102 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Event;
|
|
|
|
use App\Domains\Event\Enums\EventDateChangeType;
|
|
use App\Domains\Event\Models\EventDateChange;
|
|
use App\Domains\Event\Services\EventDateNoticeFormatter;
|
|
use App\Domains\Event\Services\EventDateTextFormatter;
|
|
use Tests\TestCase;
|
|
|
|
class EventDateNoticeFormatterTest extends TestCase
|
|
{
|
|
public function test_it_formats_singular_suspension_and_reschedule_notices(): void
|
|
{
|
|
$formatter = new EventDateNoticeFormatter(new EventDateTextFormatter);
|
|
|
|
$notices = $formatter->format(collect([
|
|
$this->change(EventDateChangeType::Suspended, '2026-10-09'),
|
|
$this->change(EventDateChangeType::Rescheduled, '2026-10-10', '2026-10-13'),
|
|
]));
|
|
|
|
$this->assertSame([
|
|
[
|
|
'type' => 'suspended',
|
|
'change_ids' => [],
|
|
'title' => 'FECHA CANCELADA!',
|
|
'message' => [
|
|
['text' => 'La fecha del ', 'bold' => false],
|
|
['text' => '09 de Octubre de 2026', 'bold' => true],
|
|
['text' => ' ha sido cancelada.', 'bold' => false],
|
|
],
|
|
],
|
|
[
|
|
'type' => 'rescheduled',
|
|
'change_ids' => [],
|
|
'title' => 'FECHA REPROGRAMADA!',
|
|
'message' => [
|
|
['text' => 'La fecha del ', 'bold' => false],
|
|
['text' => '10 de Octubre de 2026', 'bold' => true],
|
|
['text' => ' ha sido reprogramada para el ', 'bold' => false],
|
|
['text' => '13 de Octubre de 2026', 'bold' => true],
|
|
['text' => '.', 'bold' => false],
|
|
],
|
|
],
|
|
], $notices);
|
|
}
|
|
|
|
public function test_it_formats_suspension_and_reschedule_notices_for_the_storefront(): void
|
|
{
|
|
$formatter = new EventDateNoticeFormatter(new EventDateTextFormatter);
|
|
|
|
$notices = $formatter->format(collect([
|
|
$this->change(EventDateChangeType::Rescheduled, '2026-10-09', '2026-10-13'),
|
|
$this->change(EventDateChangeType::Suspended, '2026-10-09'),
|
|
$this->change(EventDateChangeType::Suspended, '2026-10-10'),
|
|
$this->change(EventDateChangeType::Rescheduled, '2026-10-10', '2026-10-14'),
|
|
]));
|
|
|
|
$this->assertSame([
|
|
[
|
|
'type' => 'suspended',
|
|
'change_ids' => [],
|
|
'title' => 'FECHAS CANCELADAS!',
|
|
'message' => [
|
|
['text' => 'Las fechas del ', 'bold' => false],
|
|
['text' => '09 y 10 de Octubre de 2026', 'bold' => true],
|
|
['text' => ' han sido canceladas.', 'bold' => false],
|
|
],
|
|
],
|
|
[
|
|
'type' => 'rescheduled',
|
|
'change_ids' => [],
|
|
'title' => 'FECHAS REPROGRAMADAS!',
|
|
'message' => [
|
|
['text' => 'Las fechas del ', 'bold' => false],
|
|
['text' => '09 y 10 de Octubre de 2026', 'bold' => true],
|
|
['text' => ' han sido reprogramadas para el ', 'bold' => false],
|
|
['text' => '13 y 14 de Octubre de 2026', 'bold' => true],
|
|
['text' => ', ', 'bold' => false],
|
|
['text' => 'respectivamente', 'bold' => true],
|
|
['text' => '.', 'bold' => false],
|
|
],
|
|
],
|
|
], $notices);
|
|
}
|
|
|
|
private function change(
|
|
EventDateChangeType $type,
|
|
string $previousDate,
|
|
?string $newDate = null,
|
|
): EventDateChange {
|
|
$change = new EventDateChange;
|
|
$change->setRawAttributes([
|
|
'change_type' => $type->value,
|
|
'previous_date' => $previousDate,
|
|
'new_date' => $newDate,
|
|
]);
|
|
|
|
return $change;
|
|
}
|
|
}
|