feat(storefront): expose event date notices

This commit is contained in:
2026-09-14 14:49:30 -03:00
parent 0d54887602
commit 61314d5166
9 changed files with 315 additions and 4 deletions

View File

@@ -0,0 +1,97 @@
<?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',
'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',
'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',
'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',
'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;
}
}

View File

@@ -35,4 +35,12 @@ class EventDateTextFormatterTest extends TestCase
],
];
}
public function test_it_formats_dates_for_use_inside_sentences(): void
{
$this->assertSame(
'09 y 10 de Octubre de 2026',
(new EventDateTextFormatter)->formatForSentence(['2026-10-10', '2026-10-09'])
);
}
}