Import/export expenses #194

This commit is contained in:
Nabeel Shahzad
2018-03-22 17:17:37 -05:00
parent 4e3a9fd9ea
commit a44204b185
32 changed files with 613 additions and 139 deletions

View File

@@ -262,6 +262,54 @@ class ImporterTest extends TestCase
$this->assertEquals('Departure Gate=4;Arrival Gate=C41', $exported['fields']);
}
/**
* Try importing the aicraft in the airports. Should fail
* @expectedException \Illuminate\Validation\ValidationException
* @throws \League\Csv\Exception
*/
public function testInvalidFileImport(): void
{
$file_path = base_path('tests/data/aircraft.csv');
$this->importSvc->importAirports($file_path);
}
/**
* Test the importing of expenses
* @throws \League\Csv\Exception
*/
public function testExpenseImporter(): void
{
$airline = factory(App\Models\Airline::class)->create(['icao' => 'VMS']);
$subfleet = factory(App\Models\Subfleet::class)->create(['type' => '744-3X-RB211']);
$aircraft = factory(App\Models\Aircraft::class)->create([
'subfleet_id' => $subfleet->id,
'registration' => '001Z',
]);
$file_path = base_path('tests/data/expenses.csv');
$this->importSvc->importExpenses($file_path);
$expenses = \App\Models\Expense::all();
$on_airline = $expenses->where('name', 'Per-Flight (multiplier, on airline)')->first();
$this->assertEquals(200, $on_airline->amount);
$this->assertEquals($airline->id, $on_airline->airline_id);
$pf = $expenses->where('name', 'Per-Flight (no muliplier)')->first();
$this->assertEquals(100, $pf->amount);
$this->assertEquals(\App\Models\Enums\ExpenseType::FLIGHT, $pf->type);
$catering = $expenses->where('name', 'Catering Staff')->first();
$this->assertEquals(1000, $catering->amount);
$this->assertEquals(\App\Models\Enums\ExpenseType::DAILY, $catering->type);
$this->assertEquals(\App\Models\Subfleet::class, $catering->ref_class);
$this->assertEquals($subfleet->id, $catering->ref_class_id);
$mnt = $expenses->where('name', 'Maintenance')->first();
$this->assertEquals(\App\Models\Aircraft::class, $mnt->ref_class);
$this->assertEquals($aircraft->id, $mnt->ref_class_id);
}
/**
* Test the flight importer
* @throws \League\Csv\Exception

9
tests/data/expenses.csv Normal file
View File

@@ -0,0 +1,9 @@
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