Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New subfleet not being attached to an airline on import #479 #505

Merged
merged 3 commits into from
Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions app/Services/ImportExport/AircraftImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Contracts\ImportExport;
use App\Models\Aircraft;
use App\Models\Airline;
use App\Models\Enums\AircraftState;
use App\Models\Enums\AircraftStatus;
use App\Models\Subfleet;
Expand Down Expand Up @@ -32,19 +33,21 @@ class AircraftImporter extends ImportExport
];

/**
* Find the subfleet specified, or just create it on the fly
* Find the subfleet specified, or just create it on the fly and attach it to the
* first airline that's been found
*
* @param $type
*
* @return Subfleet|\Illuminate\Database\Eloquent\Model|null|object|static
*/
protected function getSubfleet($type)
{
$subfleet = Subfleet::firstOrCreate([
return Subfleet::firstOrCreate([
'type' => $type,
], ['name' => $type]);

return $subfleet;
], [
'name' => $type,
'airline_id' => Airline::where('active', true)->first()->id,
]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion resources/views/admin/subfleets/table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{{ $subfleet->name }}
</a>
</td>
<td>{{ $subfleet->airline->name }}</td>
<td>{{ optional($subfleet->airline)->name }}</td>
<td>{{ $subfleet->type }}</td>
<td>{{ $subfleet->aircraft->count() }}</td>
<td class="text-right">
Expand Down
8 changes: 5 additions & 3 deletions tests/ImporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,8 @@ public function testFlightImporterEmptyCustomFields(): void
*/
public function testAircraftImporter(): void
{
$subfleet = factory(App\Models\Subfleet::class)->create(['type' => 'A32X']);
factory(App\Models\Airline::class)->create();
// $subfleet = factory(App\Models\Subfleet::class)->create(['type' => 'A32X']);

$file_path = base_path('tests/data/aircraft.csv');
$status = $this->importSvc->importAircraft($file_path);
Expand All @@ -579,8 +580,9 @@ public function testAircraftImporter(): void

$this->assertNotNull($aircraft);
$this->assertNotNull($aircraft->hex_code);
$this->assertEquals($subfleet->id, $aircraft->id);
$this->assertEquals($subfleet->type, $aircraft->subfleet->type);
$this->assertNotNull($aircraft->subfleet);
$this->assertNotNull($aircraft->subfleet->airline);
$this->assertEquals('A32X', $aircraft->subfleet->type);
$this->assertEquals('A320-211', $aircraft->name);
$this->assertEquals('N309US', $aircraft->registration);
$this->assertEquals(null, $aircraft->zfw);
Expand Down