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

@@ -309,6 +309,21 @@ class AdminAppEventControllerTest extends TestCase
->assertOk()
->assertJsonCount(1, 'data.event.dates')
->assertJsonPath('data.event.dates.0.id', $destination->id)
->assertJsonCount(1, 'data.event.date_changes')
->assertJsonPath('data.event.date_changes.0.type', 'rescheduled')
->assertJsonPath('data.event.date_changes.0.source_event_date_id', $original->id)
->assertJsonPath('data.event.date_changes.0.destination_event_date_id', $destination->id)
->assertJsonPath('data.event.date_changes.0.previous_date', '2027-10-09')
->assertJsonPath('data.event.date_changes.0.new_date', '2027-10-20')
->assertJsonPath('data.event.date_changes.0.occurred_at', fn ($value) => is_string($value))
->assertJsonMissingPath('data.event.date_changes.0.created_by_user_id')
->assertJsonCount(1, 'data.event.date_notices')
->assertJsonPath('data.event.date_notices.0.type', 'rescheduled')
->assertJsonPath('data.event.date_notices.0.title', 'FECHA REPROGRAMADA!')
->assertJsonPath('data.event.date_notices.0.message.0.text', 'La fecha del ')
->assertJsonPath('data.event.date_notices.0.message.1.text', '09 de Octubre de 2027')
->assertJsonPath('data.event.date_notices.0.message.1.bold', true)
->assertJsonPath('data.event.date_notices.0.message.3.text', '20 de Octubre de 2027')
->assertJsonPath('data.event_date_text', '20 de Octubre 2027');
$this->assertSame(
'2027-10-20 11:00:00',
@@ -344,6 +359,15 @@ class AdminAppEventControllerTest extends TestCase
->assertOk()
->assertJsonCount(1, 'data.event.dates')
->assertJsonPath('data.event.dates.0.date', '2027-10-25')
->assertJsonCount(2, 'data.event.date_changes')
->assertJsonPath('data.event.date_changes.1.type', 'rescheduled')
->assertJsonPath('data.event.date_changes.1.previous_date', '2027-10-20')
->assertJsonPath('data.event.date_changes.1.new_date', '2027-10-25')
->assertJsonPath('data.event.date_notices.0.title', 'FECHAS REPROGRAMADAS!')
->assertJsonPath('data.event.date_notices.0.message.1.text', '09 y 20 de Octubre de 2027')
->assertJsonPath('data.event.date_notices.0.message.3.text', '20 y 25 de Octubre de 2027')
->assertJsonPath('data.event.date_notices.0.message.5.text', 'respectivamente')
->assertJsonPath('data.event.date_notices.0.message.5.bold', true)
->assertJsonPath('data.event_date_text', '25 de Octubre 2027');
$this->assertSame(
'2027-10-25 11:00:00',
@@ -443,6 +467,18 @@ class AdminAppEventControllerTest extends TestCase
->assertOk()
->assertJsonCount(1, 'data.event.dates')
->assertJsonPath('data.event.dates.0.id', $otherDate->id)
->assertJsonCount(1, 'data.event.date_changes')
->assertJsonPath('data.event.date_changes.0.type', 'suspended')
->assertJsonPath('data.event.date_changes.0.source_event_date_id', $suspendedDate->id)
->assertJsonPath('data.event.date_changes.0.destination_event_date_id', null)
->assertJsonPath('data.event.date_changes.0.previous_date', '2027-10-09')
->assertJsonPath('data.event.date_changes.0.new_date', null)
->assertJsonMissingPath('data.event.date_changes.0.created_by_user_id')
->assertJsonCount(1, 'data.event.date_notices')
->assertJsonPath('data.event.date_notices.0.type', 'suspended')
->assertJsonPath('data.event.date_notices.0.title', 'FECHA CANCELADA!')
->assertJsonPath('data.event.date_notices.0.message.1.text', '09 de Octubre de 2027')
->assertJsonPath('data.event.date_notices.0.message.1.bold', true)
->assertJsonPath('data.event_date_text', '10 de Octubre 2027');
$this->assertSame(
'2027-10-10 09:00:00',

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'])
);
}
}