Files
einundzwanzig-app/tests/Feature/Api/CityVenueReadApiTest.php
T
HolgerHatGarKeineNode 0b454dfc80 🧪 Add API tests and update controllers for city and venue details
- ✏️ Added feature tests for cities and venues, including pagination limits and `withDetails` parameter handling.
- ✏️ Updated `CityController` to support `withDetails`, returning country code and flag URL while lifting pagination limits.
- ✏️ Updated `VenueController` to support `withDetails`, lifting pagination limits and enriching venue responses with city details.
2026-06-12 18:00:14 +02:00

51 lines
1.8 KiB
PHP

<?php
use App\Models\City;
use App\Models\Country;
use App\Models\Venue;
it('limits GET /api/cities to 10 entries without withDetails', function () {
City::factory()->count(11)->create(['country_id' => Country::factory()->create()->id]);
$this->getJson('/api/cities')
->assertSuccessful()
->assertJsonCount(10);
});
it('returns all cities with country code and flag on GET /api/cities?withDetails', function () {
$cities = City::factory()->count(11)->create(['country_id' => Country::factory()->create()->id]);
$response = $this->getJson('/api/cities?withDetails')
->assertSuccessful()
->assertJsonCount(11);
$first = collect($response->json())->firstWhere('id', $cities->first()->id);
expect($first)
->toHaveKeys(['id', 'name', 'country_id', 'country', 'flag'])
->and($first['country'])->toHaveKeys(['id', 'name', 'code'])
->and($first['flag'])->toContain('4x3-'.$cities->first()->country->code.'.svg');
});
it('limits GET /api/venues to 10 entries without withDetails', function () {
Venue::factory()->count(11)->create(['city_id' => City::factory()->create()->id]);
$this->getJson('/api/venues')
->assertSuccessful()
->assertJsonCount(10);
});
it('returns all venues on GET /api/venues?withDetails', function () {
$venues = Venue::factory()->count(11)->create(['city_id' => City::factory()->create()->id]);
$response = $this->getJson('/api/venues?withDetails')
->assertSuccessful()
->assertJsonCount(11);
$first = collect($response->json())->firstWhere('id', $venues->first()->id);
expect($first)
->toHaveKeys(['id', 'name', 'city_id', 'flag', 'description', 'city'])
->and($first['city']['country'])->toHaveKeys(['id', 'name', 'code']);
});