Save airport timezone (#1112)

* Fix airport timezone lookup

* Save timezone to the airport when importing
This commit is contained in:
Nabeel S 2021-03-29 15:49:34 -04:00 committed by GitHub
parent 9c4aced837
commit 96fff0248d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 2 deletions

View File

@ -46,6 +46,7 @@ class Airport extends Model
'lon', 'lon',
'hub', 'hub',
'timezone', 'timezone',
'tz',
'ground_handling_cost', 'ground_handling_cost',
'fuel_100ll_cost', 'fuel_100ll_cost',
'fuel_jeta_cost', 'fuel_jeta_cost',

View File

@ -2,7 +2,7 @@
namespace App\Services; namespace App\Services;
use App\Contracts\AirportLookup as AirportLookupProvider; use App\Contracts\AirportLookup;
use App\Contracts\Metar as MetarProvider; use App\Contracts\Metar as MetarProvider;
use App\Contracts\Service; use App\Contracts\Service;
use App\Exceptions\AirportNotFound; use App\Exceptions\AirportNotFound;
@ -23,7 +23,7 @@ class AirportService extends Service
private $metarProvider; private $metarProvider;
public function __construct( public function __construct(
AirportLookupProvider $lookupProvider, AirportLookup $lookupProvider,
AirportRepository $airportRepo, AirportRepository $airportRepo,
MetarProvider $metarProvider MetarProvider $metarProvider
) { ) {

30
tests/AirportTest.php Normal file
View File

@ -0,0 +1,30 @@
<?php
namespace Tests;
use App\Models\Airport;
/**
* Test the parsing/support class of the metar
*/
class AirportTest extends TestCase
{
public function testSavingAirportFromApiResponse()
{
// This is the response from the API
$airportResponse = [
'icao' => 'KJFK',
'iata' => 'JFK',
'name' => 'John F Kennedy International Airport',
'city' => 'New York',
'country' => 'United States',
'tz' => 'America/New_York',
'lat' => 40.63980103,
'lon' => -73.77890015,
];
$airport = new Airport($airportResponse);
$this->assertEquals($airportResponse['icao'], $airport->icao);
$this->assertEquals($airportResponse['tz'], $airport->timezone);
}
}

View File

@ -88,6 +88,16 @@ abstract class TestCase extends \Illuminate\Foundation\Testing\TestCase
}); });
} }
/**
* @param $mocks
*/
protected function addMocks($mocks)
{
$handler = HandlerStack::create($mocks);
$client = new Client(['handler' => $handler]);
$this->client->httpClient = $client;
}
/** /**
* @param $user * @param $user
* @param array $headers * @param array $headers