Tests for the CSV import fix

#1007
This commit is contained in:
Nabeel Shahzad
2021-01-25 16:49:32 -05:00
parent 5821067231
commit 3f92191126
5 changed files with 27 additions and 7 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

@@ -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

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);
}
/**

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