feat(event): add EventDateTextFormatter for formatting event dates; update Tenant model and resource to include event_date_text; create migration for event_date_text column; enhance tests for event date formatting and tenant updates
This commit is contained in:
@@ -191,6 +191,7 @@ class CatalogSchemaTest extends TestCase
|
||||
$this->assertTrue(Schema::hasColumns('tenants', [
|
||||
'event_title',
|
||||
'event_location',
|
||||
'event_date_text',
|
||||
]));
|
||||
$this->assertEqualsCanonicalizing([
|
||||
'id',
|
||||
|
||||
@@ -56,6 +56,7 @@ class AdminAppEventControllerTest extends TestCase
|
||||
'id' => $tenant->id,
|
||||
'event_title' => 'Festival Acme',
|
||||
'event_location' => 'Predio Ferial, Rosario',
|
||||
'event_date_text' => '9 de Octubre 2026',
|
||||
]);
|
||||
$this->assertDatabaseHas('event_dates', [
|
||||
'tenant_code' => $tenant->codigo,
|
||||
@@ -137,6 +138,7 @@ class AdminAppEventControllerTest extends TestCase
|
||||
'date' => '2026-11-15',
|
||||
]);
|
||||
$this->assertDatabaseMissing('event_dates', ['id' => $removedDate->id]);
|
||||
$this->assertSame('15 de Noviembre 2026', $tenant->fresh()->event_date_text);
|
||||
$this->assertDatabaseMissing('tenant_social_media', [
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'social_media_code' => 'facebook',
|
||||
@@ -148,6 +150,27 @@ class AdminAppEventControllerTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_updating_event_dates_recalculates_the_tenant_date_text(): void
|
||||
{
|
||||
$tenant = $this->createTenant('acme');
|
||||
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
||||
$payload = $this->eventPayload();
|
||||
$payload['dates'] = collect([9, 10, 11, 12])
|
||||
->map(fn (int $day): array => [
|
||||
'date' => sprintf('2026-10-%02d', $day),
|
||||
'start_time' => '09:00',
|
||||
'end_time' => '18:30',
|
||||
])
|
||||
->all();
|
||||
|
||||
$this->putJson('/api/v1/adminapp/tenant/event', $payload)->assertOk();
|
||||
|
||||
$this->assertSame(
|
||||
'9, 10, 11 y 12 de Octubre 2026',
|
||||
$tenant->fresh()->event_date_text
|
||||
);
|
||||
}
|
||||
|
||||
public function test_update_validates_event_dates_and_contact_urls(): void
|
||||
{
|
||||
$tenant = $this->createTenant('acme');
|
||||
|
||||
@@ -52,6 +52,7 @@ class BootstrapTenantControllerTest extends TestCase
|
||||
'footer_bg_color' => '#ffffff',
|
||||
'header_logo_id' => $headerAttachment->id,
|
||||
'footer_logo_id' => $footerAttachment->id,
|
||||
'event_date_text' => '9, 10, 11 y 12 de Octubre 2026',
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/tenants/bootstrap/acme.com');
|
||||
@@ -64,6 +65,7 @@ class BootstrapTenantControllerTest extends TestCase
|
||||
->assertJsonPath('data.secondary_color', '#00ff00')
|
||||
->assertJsonPath('data.danger_color', '#0000ff')
|
||||
->assertJsonPath('data.success_color', '#00ff00')
|
||||
->assertJsonPath('data.event_date_text', '9, 10, 11 y 12 de Octubre 2026')
|
||||
->assertJsonPath('data.header_bg_color', '#ffffff')->assertJsonPath('data.footer_bg_color', '#ffffff');
|
||||
|
||||
$headerUrl = $response->json('data.header_logo');
|
||||
|
||||
38
tests/Unit/Event/EventDateTextFormatterTest.php
Normal file
38
tests/Unit/Event/EventDateTextFormatterTest.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Event;
|
||||
|
||||
use App\Domains\Event\Services\EventDateTextFormatter;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class EventDateTextFormatterTest extends TestCase
|
||||
{
|
||||
/** @param array<int, string> $dates */
|
||||
#[DataProvider('dateCases')]
|
||||
public function test_it_formats_event_dates_in_spanish(array $dates, ?string $expected): void
|
||||
{
|
||||
$this->assertSame($expected, (new EventDateTextFormatter)->format($dates));
|
||||
}
|
||||
|
||||
/** @return array<string, array{array<int, string>, string|null}> */
|
||||
public static function dateCases(): array
|
||||
{
|
||||
return [
|
||||
'no dates' => [[], null],
|
||||
'one date' => [['2026-10-09'], '9 de Octubre 2026'],
|
||||
'same month sorted' => [
|
||||
['2026-10-12', '2026-10-09', '2026-10-11', '2026-10-10'],
|
||||
'9, 10, 11 y 12 de Octubre 2026',
|
||||
],
|
||||
'different months' => [
|
||||
['2026-11-01', '2026-10-31'],
|
||||
'31 de Octubre y 1 de Noviembre 2026',
|
||||
],
|
||||
'different years' => [
|
||||
['2027-01-01', '2026-12-31'],
|
||||
'31 de Diciembre 2026 y 1 de Enero 2027',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user