From d3ec0f4de39c3353bbe525338b49868392f4124c Mon Sep 17 00:00:00 2001 From: Nabeel S Date: Fri, 21 May 2021 10:52:47 -0400 Subject: [PATCH] 5 char ICAO support #1052 (#1198) --- app/Database/factories/AirportFactory.php | 2 +- .../2021_05_21_141152_increase_icao_sizes.php | 26 +++++++++++++++++++ tests/AirportTest.php | 3 --- tests/ApiTest.php | 18 +++++++++++++ 4 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 app/Database/migrations/2021_05_21_141152_increase_icao_sizes.php diff --git a/app/Database/factories/AirportFactory.php b/app/Database/factories/AirportFactory.php index f015a1b7..af7de5c4 100644 --- a/app/Database/factories/AirportFactory.php +++ b/app/Database/factories/AirportFactory.php @@ -11,7 +11,7 @@ if (!function_exists('createFactoryICAO')) { $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $max = strlen($characters) - 1; $string = ''; - for ($i = 0; $i < 4; $i++) { + for ($i = 0; $i < 5; $i++) { try { $string .= $characters[random_int(0, $max)]; } catch (Exception $e) { diff --git a/app/Database/migrations/2021_05_21_141152_increase_icao_sizes.php b/app/Database/migrations/2021_05_21_141152_increase_icao_sizes.php new file mode 100644 index 00000000..37aa65ca --- /dev/null +++ b/app/Database/migrations/2021_05_21_141152_increase_icao_sizes.php @@ -0,0 +1,26 @@ +string('iata', 5)->change(); + $table->string('icao', 5)->change(); + }); + + Schema::table('pireps', function (Blueprint $table) { + $table->string('dpt_airport_id', 5)->change(); + $table->string('arr_airport_id', 5)->change(); + $table->string('alt_airport_id', 5)->change(); + }); + } +} diff --git a/tests/AirportTest.php b/tests/AirportTest.php index 9907cd10..fe828422 100644 --- a/tests/AirportTest.php +++ b/tests/AirportTest.php @@ -4,9 +4,6 @@ namespace Tests; use App\Models\Airport; -/** - * Test the parsing/support class of the metar - */ class AirportTest extends TestCase { public function testSavingAirportFromApiResponse() diff --git a/tests/ApiTest.php b/tests/ApiTest.php index 74c1020a..7e73b3bb 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -166,6 +166,24 @@ class ApiTest extends TestCase $this->get('/api/airports/UNK')->assertStatus(404); } + /** + * Make sure the airport data is returned + */ + public function testAirportRequest5Char() + { + $this->user = factory(User::class)->create(); + + /** @var Airport $airport */ + $airport = factory(Airport::class)->create(['icao' => '5Char']); + + $response = $this->get('/api/airports/'.$airport->icao); + + $response->assertStatus(200); + $response->assertJson(['data' => ['icao' => $airport->icao]]); + + $this->get('/api/airports/UNK')->assertStatus(404); + } + /** * Get all the airports, test the pagination */