diff --git a/app/Services/AirportService.php b/app/Services/AirportService.php index 179fdc0e..ac93b867 100644 --- a/app/Services/AirportService.php +++ b/app/Services/AirportService.php @@ -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, diff --git a/app/Services/ImportExport/FlightImporter.php b/app/Services/ImportExport/FlightImporter.php index d2fd6a91..9cd14946 100644 --- a/app/Services/ImportExport/FlightImporter.php +++ b/app/Services/ImportExport/FlightImporter.php @@ -51,8 +51,13 @@ class FlightImporter extends ImportExport 'fields' => 'nullable', ]; + /** @var AirportService */ private $airportSvc; + + /** @var FareService */ private $fareSvc; + + /** @var FlightService */ private $flightSvc; /** diff --git a/app/Services/ImportService.php b/app/Services/ImportService.php index c761bcc4..d49007e2 100644 --- a/app/Services/ImportService.php +++ b/app/Services/ImportService.php @@ -117,12 +117,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 trim($val); })->toArray(); // Try to validate diff --git a/tests/ImporterTest.php b/tests/ImporterTest.php index eaa2a10f..6484668f 100644 --- a/tests/ImporterTest.php +++ b/tests/ImporterTest.php @@ -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); } /** diff --git a/tests/data/flights-update.csv b/tests/data/flights-update.csv new file mode 100644 index 00000000..50b69fe2 --- /dev/null +++ b/tests/data/flights-update.csv @@ -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