fix dashboard and apis
PHP Tests / php-tests (push) Failing after 9m1s

This commit is contained in:
Nyan Lin Paing
2026-08-16 23:50:39 +07:00
parent 60413bdebf
commit 8d74ac74cd
26 changed files with 638 additions and 55 deletions
@@ -3,7 +3,7 @@
use Illuminate\Support\Facades\Route;
use Modules\Routing\Http\Controllers\EvRouteController;
Route::prefix('api/v1')->middleware(['api', 'auth:sanctum', 'throttle:api-read'])->group(function () {
Route::prefix('api/v1')->middleware(['api', 'api.auth', 'throttle:api-read'])->group(function () {
Route::get('/routes', [EvRouteController::class, 'index'])->name('routing.routes.index');
Route::get('/routes/{route}', [EvRouteController::class, 'show'])->name('routing.routes.show');
Route::get('/routes/{route}/pricing', [EvRouteController::class, 'pricing'])->name('routing.routes.pricing');
@@ -25,9 +25,10 @@ class EvRouteController extends Controller
public function index(Request $request): AnonymousResourceCollection
{
$filters = $request->only(['company', 'from', 'to', 'date']);
$page = $request->integer('page', 1);
$routes = Cache::tags(self::CACHE_TAG)->remember(
'routes:index:'.md5(json_encode($filters)),
'routes:index:'.md5(json_encode($filters + ['page' => $page])),
now()->addMinutes(self::CACHE_TTL_MINUTES),
fn () => EvRoute::query()
->where('is_active', true)
@@ -37,7 +38,7 @@ class EvRouteController extends Controller
// `date` is accepted for forward-compatibility with future per-date capacity
// checks (domain.md §7), but v1 has no route-level calendar to filter against.
->with(self::EAGER_LOADS)
->get(),
->paginate(),
);
return EvRouteResource::collection($routes);
@@ -78,6 +78,16 @@ test('filters routes by company, from, and to', function () {
->assertJsonPath('data.0.id', $matching->id);
});
test('paginates routes', function () {
EvRoute::factory()->count(20)->create(['is_active' => true]);
$this->withHeader('Authorization', "Bearer {$this->token}")
->getJson('/api/v1/routes')
->assertSuccessful()
->assertJsonCount(15, 'data')
->assertJsonPath('meta.total', 20);
});
test('shows a single active route', function () {
$route = EvRoute::factory()->create(['is_active' => true]);