Add validation to importers to fix invalid/empty columns #222

This commit is contained in:
Nabeel Shahzad
2018-03-30 17:27:29 -05:00
parent bd30b1f900
commit 63544088cd
21 changed files with 124 additions and 68 deletions

View File

@@ -277,6 +277,18 @@ class ImporterTest extends TestCase
$this->importSvc->importAirports($file_path);
}
/**
* Try importing the aicraft in the airports. Should fail because of
* empty/invalid rows
*/
public function testEmptyCols(): void
{
$file_path = base_path('tests/data/expenses_empty_rows.csv');
$status = $this->importSvc->importExpenses($file_path);
$this->assertCount(8, $status['success']);
$this->assertCount(0, $status['errors']);
}
/**
* Test the importing of expenses
* @throws \Illuminate\Validation\ValidationException
@@ -291,7 +303,10 @@ class ImporterTest extends TestCase
]);
$file_path = base_path('tests/data/expenses.csv');
$this->importSvc->importExpenses($file_path);
$status = $this->importSvc->importExpenses($file_path);
$this->assertCount(8, $status['success']);
$this->assertCount(0, $status['errors']);
$expenses = \App\Models\Expense::all();
@@ -320,7 +335,10 @@ class ImporterTest extends TestCase
public function testFareImporter(): void
{
$file_path = base_path('tests/data/fares.csv');
$this->importSvc->importFares($file_path);
$status = $this->importSvc->importFares($file_path);
$this->assertCount(3, $status['success']);
$this->assertCount(0, $status['errors']);
$fares = \App\Models\Fare::all();
@@ -358,7 +376,10 @@ class ImporterTest extends TestCase
[$airline, $subfleet] = $this->insertFlightsScaffoldData();
$file_path = base_path('tests/data/flights.csv');
$this->importSvc->importFlights($file_path);
$status = $this->importSvc->importFlights($file_path);
$this->assertCount(1, $status['success']);
$this->assertCount(1, $status['errors']);
// See if it imported
$flight = \App\Models\Flight::where([
@@ -425,7 +446,10 @@ class ImporterTest extends TestCase
$subfleet = factory(App\Models\Subfleet::class)->create(['type' => 'A32X']);
$file_path = base_path('tests/data/aircraft.csv');
$this->importSvc->importAircraft($file_path);
$status = $this->importSvc->importAircraft($file_path);
$this->assertCount(1, $status['success']);
$this->assertCount(1, $status['errors']);
// See if it imported
$aircraft = \App\Models\Aircraft::where([
@@ -444,7 +468,10 @@ class ImporterTest extends TestCase
public function testAirportImporter(): void
{
$file_path = base_path('tests/data/airports.csv');
$this->importSvc->importAirports($file_path);
$status = $this->importSvc->importAirports($file_path);
$this->assertCount(1, $status['success']);
$this->assertCount(1, $status['errors']);
// See if it imported
$airport = \App\Models\Airport::where([
@@ -468,7 +495,10 @@ class ImporterTest extends TestCase
$airline = factory(App\Models\Airline::class)->create(['icao' => 'VMS']);
$file_path = base_path('tests/data/subfleets.csv');
$this->importSvc->importSubfleets($file_path);
$status = $this->importSvc->importSubfleets($file_path);
$this->assertCount(1, $status['success']);
$this->assertCount(1, $status['errors']);
// See if it imported
$subfleet = \App\Models\Subfleet::where([

View File

@@ -1,2 +1,3 @@
subfleet,name,registration,hex_code,status
A32X,A320-211,N309US,,
74X,747 400, ,,
1 subfleet name registration hex_code status
2 A32X A320-211 N309US
3 74X 747 400

View File

@@ -0,0 +1,3 @@
subfleet,name,registration,hex_code,status
A32X,A320-211,N309US,,
, B744-GE, N304,,
1 subfleet name registration hex_code status
2 A32X A320-211 N309US
3 B744-GE N304

View File

@@ -1,2 +1,3 @@
icao,iata,name,location,country,timezone,hub,lat,lon
KAUS,AUS,Austin-Bergstrom,"Austin, Texas, USA", United States,America/Chicago,1,30.1945,-97.6699
KJFK,JFK,Kennery,"Queens, New York, USA", United States,America/New_York,0,30.1945,abcd
1 icao iata name location country timezone hub lat lon
2 KAUS AUS Austin-Bergstrom Austin, Texas, USA United States America/Chicago 1 30.1945 -97.6699
3 KJFK JFK Kennery Queens, New York, USA United States America/New_York 0 30.1945 abcd

View File

@@ -0,0 +1,11 @@
airline,name,amount,type,charge_to_user,multiplier,active,ref_class,ref_class_id
,"Per-Flight (no muliplier)",100,F,0,0,1,,
,"Per-Flight (multiplier)",100,F,0,1,1,,
VMS,"Per-Flight (multiplier, on airline)",200,F,0,1,1,,
,"A daily fee",800,D,0,0,1,,
,"A monthly fee",5000,M,0,0,1,,
,Catering,1000,F,0,0,1,Subfleet,744-3X-RB211
,"Catering Staff",1000,D,0,0,1,Subfleet,744-3X-RB211
,Maintenance,1000,D,0,0,1,App\Models\Aircraft,001Z
1 airline name amount type charge_to_user multiplier active ref_class ref_class_id
2 Per-Flight (no muliplier) 100 F 0 0 1
3 Per-Flight (multiplier) 100 F 0 1 1
4 VMS Per-Flight (multiplier, on airline) 200 F 0 1 1
5 A daily fee 800 D 0 0 1
6 A monthly fee 5000 M 0 0 1
7 Catering 1000 F 0 0 1 Subfleet 744-3X-RB211
8 Catering Staff 1000 D 0 0 1 Subfleet 744-3X-RB211
9 Maintenance 1000 D 0 0 1 App\Models\Aircraft 001Z

View File

@@ -1,2 +1,3 @@
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?,Departure Gate=4;Arrival Gate=C41
" ",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?,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 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? Departure Gate=4;Arrival Gate=C41
3 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? Departure Gate=4;Arrival Gate=C41

View File

@@ -1,2 +1,3 @@
airline,type,name,fares
VMS,A32X,Airbus A320,Y;B?capacity=100&price=500%
VMS, ,Boeing 747-400,Y;B?capacity=100&price=500%
1 airline type name fares
2 VMS A32X Airbus A320 Y;B?capacity=100&price=500%
3 VMS Boeing 747-400 Y;B?capacity=100&price=500%