Fix blank/empty field being returned as invalid object #222

This commit is contained in:
Nabeel Shahzad
2018-03-30 18:53:43 -05:00
parent 2c726f6c52
commit f2952c6567
3 changed files with 44 additions and 0 deletions

View File

@@ -129,6 +129,10 @@ class ImportExport
# No multiple values in here, just a straight value
if (\count($split_values) === 1) {
if(trim($split_values[0]) === '') {
return [];
}
return [$split_values[0]];
}

View File

@@ -57,6 +57,10 @@ class ImporterTest extends TestCase
public function testConvertStringtoObjects(): void
{
$tests = [
[
'input' => '',
'expected' => [],
],
[
'input' => 'gate',
'expected' => ['gate']
@@ -139,6 +143,10 @@ class ImporterTest extends TestCase
public function testConvertObjectToString(): void
{
$tests = [
[
'input' => '',
'expected' => ''
],
[
'input' => ['gate'],
'expected' => 'gate',
@@ -440,6 +448,36 @@ class ImporterTest extends TestCase
$this->assertCount(1, $subfleets);
}
/**
* Test the flight importer
* @throws \Illuminate\Validation\ValidationException
*/
public function testFlightImporterEmptyCustomFields(): void
{
[$airline, $subfleet] = $this->insertFlightsScaffoldData();
$file_path = base_path('tests/data/flights_empty_fields.csv');
$status = $this->importSvc->importFlights($file_path);
$this->assertCount(1, $status['success']);
$this->assertCount(0, $status['errors']);
// See if it imported
$flight = \App\Models\Flight::where([
'airline_id' => $airline->id,
'flight_number' => '1972'
])->first();
$this->assertNotNull($flight);
// Check the custom fields entered
$fields = \App\Models\FlightFieldValue::where([
'flight_id' => $flight->id,
])->get();
$this->assertCount(0, $fields);
}
/**
* @throws \Illuminate\Validation\ValidationException
*/

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,route,notes,active,subfleets,fares,fields
VMS,1972,,,KAUS,KJFK,KLGA,15,0810 CST,1235 EST,350,1477,207,J,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?,
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 route notes active subfleets fares fields
2 VMS 1972 KAUS KJFK KLGA 15 0810 CST 1235 EST 350 1477 207 J 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?