Compare commits

...

3 Commits

Author SHA1 Message Date
Nabeel Shahzad
c97977de9a Include all enums in aliases 2021-01-25 17:07:11 -05:00
Nabeel Shahzad
bda1a91117 Return null on empty value 2021-01-25 17:03:48 -05:00
Nabeel Shahzad
3f92191126 Tests for the CSV import fix
#1007
2021-01-25 16:49:32 -05:00
7 changed files with 50 additions and 17 deletions

View File

@@ -101,7 +101,7 @@ class AirportService extends Service
}
// Don't lookup the airport, so just add in something generic
if (!setting('general.auto_airport_lookup')) {
if (!setting('general.auto_airport_lookup', false)) {
$airport = new Airport([
'id' => $icao,
'icao' => $icao,

View File

@@ -51,8 +51,13 @@ class FlightImporter extends ImportExport
'fields' => 'nullable',
];
/** @var AirportService */
private $airportSvc;
/** @var FareService */
private $fareSvc;
/** @var FlightService */
private $flightSvc;
/**

View File

@@ -118,11 +118,7 @@ class ImportService extends Service
// turn it into a collection and run some filtering
$row = collect($row)->map(function ($val, $index) {
$val = trim($val);
if ($val === '') {
return;
}
return $val;
return empty($val) ? null : $val;
})->toArray();
// Try to validate

View File

@@ -131,10 +131,22 @@ return [
'Yaml' => Symfony\Component\Yaml\Yaml::class,
// ENUMS
'ActiveState' => App\Models\Enums\ActiveState::class,
'UserState' => App\Models\Enums\UserState::class,
'PirepSource' => App\Models\Enums\PirepSource::class,
'PirepState' => App\Models\Enums\PirepState::class,
'PirepStatus' => App\Models\Enums\PirepStatus::class,
'AcarsType' => App\Models\Enums\AcarsType::class,
'ActiveState' => App\Models\Enums\ActiveState::class,
'AircraftState' => App\Models\Enums\AircraftState::class,
'AircraftStatus' => App\Models\Enums\AircraftStatus::class,
'Days' => App\Models\Enums\Days::class,
'ExpenseType' => App\Models\Enums\ExpenseType::class,
'FareType' => App\Models\Enums\FareType::class,
'FlightType' => App\Models\Enums\FlightType::class,
'FuelType' => App\Models\Enums\FuelType::class,
'JournalType' => App\Models\Enums\JournalType::class,
'NavaidType' => App\Models\Enums\NavaidType::class,
'PageType' => App\Models\Enums\PageType::class,
'PirepFieldSource' => App\Models\Enums\PirepFieldSource::class,
'PirepSource' => App\Models\Enums\PirepSource::class,
'PirepState' => App\Models\Enums\PirepState::class,
'PirepStatus' => App\Models\Enums\PirepStatus::class,
'UserState' => App\Models\Enums\UserState::class,
],
];

View File

@@ -467,6 +467,11 @@ class ImporterTest extends TestCase
*/
public function testFlightImporter(): void
{
$this->updateSetting('general.auto_airport_lookup', false);
factory(Airport::class)->create(['icao' => 'KAUS']);
factory(Airport::class)->create(['icao' => 'KJFK']);
[$airline, $subfleet] = $this->insertFlightsScaffoldData();
$file_path = base_path('tests/data/flights.csv');
@@ -531,6 +536,19 @@ class ImporterTest extends TestCase
// Check the subfleets
$subfleets = $flight->subfleets;
$this->assertCount(1, $subfleets);
// Reimport, see that data updates
$file_path = base_path('tests/data/flights-update.csv');
$status = $this->importSvc->importFlights($file_path);
$flight = Flight::where([
'airline_id' => $airline->id,
'flight_number' => '1972',
])->first();
$this->assertCount(1, $status['success']);
$this->assertEquals('12:00 CST', $flight->dpt_time);
$this->assertEquals('18:35 EST', $flight->arr_time);
}
/**
@@ -634,8 +652,8 @@ class ImporterTest extends TestCase
$this->assertEquals(true, $airport->hub);
$this->assertEquals('30.1945', $airport->lat);
$this->assertEquals('-97.6699', $airport->lon);
$this->assertEquals(0.0, $airport->ground_handling_cost);
$this->assertEquals(setting('airports.default_jet_a_fuel_cost'), $airport->fuel_jeta_cost);
$this->assertEquals(250, $airport->ground_handling_cost);
$this->assertEquals(0.8, $airport->fuel_jeta_cost); // should be updated
// See if it imported
$airport = Airport::where([

View File

@@ -1,4 +1,4 @@
icao,iata,name,location,country,timezone,hub,lat,lon,ground_handling_cost,fuel_100ll_cost,fuel_jeta_cost,fuel_mogas_cost
KAUS,AUS,Austin-Bergstrom,"Austin, Texas, USA", United States,America/Chicago,1,30.1945,-97.6699,0,,,
KSFO,SFO,San Francisco,"San Francisco, California, USA", United States,America/California,1,30.1945,-97.6699,,,0.9,
KJFK,JFK,Kennedy,"Queens, New York, USA", United States,America/New_York,0,30.1945,abcd,150,,0.8,
icao,iata,name,location,country,timezone,hub,lat,lon,ground_handling_cost,fuel_100ll_cost,fuel_jeta_cost,fuel_mogas_cost
KAUS,AUS,Austin-Bergstrom,"Austin, Texas, USA", United States,America/Chicago,1,30.1945,-97.6699,250,0.8,0.8,0.8
KSFO,SFO,San Francisco,"San Francisco, California, USA", United States,America/California,1,30.1945,-97.6699,,,0.9,
KJFK,JFK,Kennedy,"Queens, New York, USA", United States,America/New_York,0,30.1945,abcd,150,,0.8,
1 icao iata name location country timezone hub lat lon ground_handling_cost fuel_100ll_cost fuel_jeta_cost fuel_mogas_cost
2 KAUS AUS Austin-Bergstrom Austin, Texas, USA United States America/Chicago 1 30.1945 -97.6699 0 250 0.8 0.8 0.8
3 KSFO SFO San Francisco San Francisco, California, USA United States America/California 1 30.1945 -97.6699 0.9
4 KJFK JFK Kennedy Queens, New York, USA United States America/New_York 0 30.1945 abcd 150 0.8

View File

@@ -0,0 +1,2 @@
airline,flight_number,route_code,route_leg,dpt_airport,arr_airport,alt_airport,days,dpt_time,arr_time,level,distance,flight_time,flight_type,load_factor, load_factor_variance,pilot_pay,route,notes,active,subfleets,fares,fields
VMS,1972, ,,KAUS,KJFK,KLGA,15,12:00 CST,18:35 EST,350,1477,207,J,85,0,100, ILEXY2 ZENZI LFK ELD J29 MEM Q29 JHW J70 STENT J70 MAGIO J70 LVZ LENDY6,"Just a flight",1,A32X,Y?price=300&cost=100&capacity=130;F?price=600&cost=400;B?,Departure Gate=4;Arrival Gate=C41
1 airline flight_number route_code route_leg dpt_airport arr_airport alt_airport days dpt_time arr_time level distance flight_time flight_type load_factor load_factor_variance pilot_pay route notes active subfleets fares fields
2 VMS 1972 KAUS KJFK KLGA 15 12:00 CST 18:35 EST 350 1477 207 J 85 0 100 ILEXY2 ZENZI LFK ELD J29 MEM Q29 JHW J70 STENT J70 MAGIO J70 LVZ LENDY6 Just a flight 1 A32X Y?price=300&cost=100&capacity=130;F?price=600&cost=400;B? Departure Gate=4;Arrival Gate=C41