Add Popular Routes

Curated from/to destination pairs for marketing content, editable via a
Filament resource and served publicly (no auth, IP-throttled like CMS
pages) through GET /api/v1/popular-routes. The API response trims each
nested destination down to id/name/mm_name rather than the full catalog
resource.
This commit is contained in:
Nyan Lin Paing
2026-08-30 14:52:39 +07:00
parent 76f75c5581
commit b6934e1fb5
16 changed files with 622 additions and 0 deletions
@@ -0,0 +1,59 @@
<?php
use Modules\Catalog\Models\Destination;
use Modules\Routing\Models\PopularRoute;
test('lists active popular routes with nested destinations, no auth required', function () {
$from = Destination::factory()->create();
$to = Destination::factory()->create();
PopularRoute::factory()->create([
'from_destination_id' => $from->id,
'to_destination_id' => $to->id,
'description' => 'A scenic drive.',
'mm_description' => 'သာယာသောခရီးစဉ်။',
'is_active' => true,
]);
PopularRoute::factory()->create(['is_active' => false]);
$this->getJson('/api/v1/popular-routes')
->assertSuccessful()
->assertJsonCount(1, 'data')
->assertJsonPath('data.0.from_destination.id', $from->id)
->assertJsonPath('data.0.to_destination.id', $to->id)
->assertJsonPath('data.0.description', 'A scenic drive.')
->assertJsonPath('data.0.mm_description', 'သာယာသောခရီးစဉ်။');
});
test('the nested destinations only expose id, name and mm_name, not the full catalog fields', function () {
$from = Destination::factory()->create();
$to = Destination::factory()->create();
PopularRoute::factory()->create([
'from_destination_id' => $from->id,
'to_destination_id' => $to->id,
'is_active' => true,
]);
$this->getJson('/api/v1/popular-routes')
->assertSuccessful()
->assertJsonPath('data.0.from_destination', [
'id' => $from->id,
'name' => $from->name,
'mm_name' => $from->mm_name,
])
->assertJsonPath('data.0.to_destination', [
'id' => $to->id,
'name' => $to->name,
'mm_name' => $to->mm_name,
]);
});
test('an inactive popular route is excluded from the list', function () {
PopularRoute::factory()->create(['is_active' => false]);
$this->getJson('/api/v1/popular-routes')
->assertSuccessful()
->assertJsonCount(0, 'data');
});