A free open source IT asset/license management system
Render time for checkouts, not “all day” in calendar view
snipee8f643fc9537
diff --git a/app/Models/Asset.php b/app/Models/Asset.phpindex cb3a29a315..eb98907628 100644--- a/app/Models/Asset.php+++ b/app/Models/Asset.php@@ -1855,14 +1855,20 @@ class Asset extends Depreciable*/public function calendarEventDefinitions(): array{- // Every entry marked all_day: true. Cast metadata on Asset is- // mixed (next_audit_date is 'datetime:m-d-Y', expected_checkin- // and last_checkout are 'datetime', asset_eol_date has no cast- // at all) so cast-based auto-detection wouldn't catch them- // uniformly. Calendar context also doesn't need hour-precision- // for any of these - an audit-due date, an EOL date, or the- // day something got checked out reads as an all-day marker on- // the calendar even for columns that happen to store a time.+ // Most entries are marked all_day: true because they represent+ // date-only obligations (an audit due on 2026-09-15, an EOL+ // date, a warranty expiration). The mixed cast metadata on+ // Asset (next_audit_date is 'datetime:m-d-Y', expected_checkin+ // and last_checkout are 'datetime', asset_eol_date has no cast)+ // means cast-based auto-detection wouldn't catch them+ // uniformly, so the flag is explicit per entry.+ //+ // last_checkout is the one exception. Checkout happens at a+ // specific moment in time, so the calendar shows it at that+ // hour rather than as an all-day marker. The transformer's+ // isAllDayField() reads all_day directly from this array, so+ // flipping the flag here is all that's needed to switch the+ // rendered event's shape.return [['field' => 'next_audit_date',@@ -1877,7 +1883,7 @@ class Asset extends Depreciable['field' => 'last_checkout','event_type' => 'asset.checkout',- 'all_day' => true,+ 'all_day' => false,],['field' => 'asset_eol_date',diff --git a/tests/Feature/CalendarEvents/AssetEventDefinitionsTest.php b/tests/Feature/CalendarEvents/AssetEventDefinitionsTest.phpnew file mode 100644index 0000000000..10bd8ea1fa--- /dev/null+++ b/tests/Feature/CalendarEvents/AssetEventDefinitionsTest.php@@ -0,0 +1,125 @@+<?php++namespace Tests\Feature\CalendarEvents;++use App\Http\Transformers\CalendarEventsTransformer;+use App\Models\Asset;+use App\Models\CalendarEvent;+use Tests\TestCase;++/**+ * Coverage for Asset::calendarEventDefinitions() specifically. The+ * shared HasCalendarEvents behavior (observer wiring, soft-delete+ * cascade, reconcile) is covered by CalendarEventsSyncTest against+ * Maintenance. This file pins the Asset-side entries and the+ * per-entry all_day semantics.+ *+ * Notable: last_checkout publishes as a NON all-day event because+ * checkouts happen at a specific moment in time. Every other Asset+ * event type is a date-only obligation (audit_due, expected_checkin,+ * eol, warranty_expiration) and stays all-day.+ */+class AssetEventDefinitionsTest extends TestCase+{+ public function test_setting_last_checkout_publishes_asset_checkout_calendar_event(): void+ {+ $checkoutAt = now()->setTime(14, 30, 0);+ $asset = Asset::factory()->create([+ 'last_checkout' => $checkoutAt,+ ]);++ $event = CalendarEvent::where('source_type', Asset::class)+ ->where('source_id', $asset->id)+ ->where('source_field', 'last_checkout')+ ->first();++ $this->assertNotNull($event);+ $this->assertSame('asset.checkout', $event->event_type);+ $this->assertTrue($event->start->equalTo($checkoutAt));+ }++ public function test_asset_checkout_event_renders_with_time_of_day_not_all_day(): void+ {+ // The transformer reads all_day directly from+ // calendarEventDefinitions() at render time. Since checkouts+ // happen at a specific moment, the event should surface with+ // an ISO 8601 timestamp (time-of-day) rather than a date-only+ // string. Every other Asset event stays all-day.+ $checkoutAt = now()->setTime(9, 15, 0);+ $asset = Asset::factory()->create([+ 'last_checkout' => $checkoutAt,+ ]);++ $row = CalendarEvent::where('source_type', Asset::class)+ ->where('source_id', $asset->id)+ ->where('source_field', 'last_checkout')+ ->first();++ $transformed = (new CalendarEventsTransformer)->transformCalendarEvents(+ [$row],+ [Asset::class => Asset::query()->whereKey($asset->id)->get()->keyBy('id')],+ );++ $this->assertCount(1, $transformed);+ $this->assertFalse(+ $transformed[0]['allDay'],+ 'asset.checkout should render as a specific-time event, not all-day.'+ );+ $this->assertStringContainsString(+ 'T',+ (string) $transformed[0]['start'],+ 'A non-all-day event should serialize its start as an ISO 8601 timestamp with a time component.'+ );+ }++ public function test_setting_expected_checkin_still_publishes_all_day_calendar_event(): void+ {+ // Positive-side regression guard for the four all-day Asset+ // event types. If a future edit accidentally flips one of+ // these to non-all-day (or drops it entirely), the calendar+ // will change shape and this test catches it.+ $asset = Asset::factory()->create([+ 'expected_checkin' => now()->addDays(7),+ ]);++ $row = CalendarEvent::where('source_type', Asset::class)+ ->where('source_id', $asset->id)+ ->where('source_field', 'expected_checkin')+ ->first();++ $this->assertNotNull($row);+ $this->assertSame('asset.expected_checkin', $row->event_type);++ $transformed = (new CalendarEventsTransformer)->transformCalendarEvents(+ [$row],+ [Asset::class => Asset::query()->whereKey($asset->id)->get()->keyBy('id')],+ );++ $this->assertTrue(+ $transformed[0]['allDay'],+ 'expected_checkin should render as an all-day event because it represents a date-only obligation.'+ );+ }++ public function test_setting_next_audit_date_still_publishes_all_day_calendar_event(): void+ {+ $asset = Asset::factory()->create([+ 'next_audit_date' => now()->addDays(30),+ ]);++ $row = CalendarEvent::where('source_type', Asset::class)+ ->where('source_id', $asset->id)+ ->where('source_field', 'next_audit_date')+ ->first();++ $this->assertNotNull($row);+ $this->assertSame('asset.audit_due', $row->event_type);++ $transformed = (new CalendarEventsTransformer)->transformCalendarEvents(+ [$row],+ [Asset::class => Asset::query()->whereKey($asset->id)->get()->keyBy('id')],+ );++ $this->assertTrue($transformed[0]['allDay']);+ }+}