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
@@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Route;
use Modules\Catalog\Http\Controllers\DestinationController;
use Modules\Catalog\Http\Controllers\EvCompanyController;
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('/companies', [EvCompanyController::class, 'index'])->name('catalog.companies.index');
Route::get('/destinations', [DestinationController::class, 'index'])->name('catalog.destinations.index');
});
@@ -2,6 +2,7 @@
namespace Modules\Catalog\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Illuminate\Routing\Controller;
use Modules\Catalog\Http\Resources\DestinationResource;
@@ -9,10 +10,23 @@ use Modules\Catalog\Models\Destination;
class DestinationController extends Controller
{
public function index(): AnonymousResourceCollection
public function index(Request $request): AnonymousResourceCollection
{
$terms = array_filter(array_map(
trim(...),
explode(',', (string) $request->string('search')),
));
return DestinationResource::collection(
Destination::query()->where('is_active', true)->get()
Destination::query()
->where('is_active', true)
->when($terms !== [], fn ($query) => $query->where(function ($query) use ($terms) {
foreach ($terms as $term) {
$query->orWhere('name', 'ilike', "%{$term}%")
->orWhere('mm_name', 'ilike', "%{$term}%");
}
}))
->paginate()
);
}
}
@@ -12,7 +12,7 @@ class EvCompanyController extends Controller
public function index(): AnonymousResourceCollection
{
return EvCompanyResource::collection(
EvCompany::query()->where('is_active', true)->get()
EvCompany::query()->where('is_active', true)->paginate()
);
}
}
@@ -30,6 +30,36 @@ test('lists active destinations', function () {
->assertJsonFragment(['id' => $active->id]);
});
test('paginates companies and destinations', function () {
EvCompany::factory()->count(20)->create(['is_active' => true]);
Destination::factory()->count(20)->create(['is_active' => true]);
$this->withHeader('Authorization', "Bearer {$this->token}")
->getJson('/api/v1/companies')
->assertSuccessful()
->assertJsonCount(15, 'data')
->assertJsonPath('meta.total', 20);
$this->withHeader('Authorization', "Bearer {$this->token}")
->getJson('/api/v1/destinations')
->assertSuccessful()
->assertJsonCount(15, 'data')
->assertJsonPath('meta.total', 20);
});
test('searches destinations by comma-separated terms', function () {
$yangon = Destination::factory()->create(['is_active' => true, 'name' => 'Yangon']);
$mandalay = Destination::factory()->create(['is_active' => true, 'name' => 'Mandalay']);
Destination::factory()->create(['is_active' => true, 'name' => 'Bagan']);
$this->withHeader('Authorization', "Bearer {$this->token}")
->getJson('/api/v1/destinations?search=yangon,mandalay')
->assertSuccessful()
->assertJsonCount(2, 'data')
->assertJsonFragment(['id' => $yangon->id])
->assertJsonFragment(['id' => $mandalay->id]);
});
test('companies endpoint rejects unauthenticated requests', function () {
$this->getJson('/api/v1/companies')->assertUnauthorized();
});