2019-11-19 23:06:07 +08:00
|
|
|
<?php
|
|
|
|
|
2020-05-23 23:43:29 +08:00
|
|
|
namespace Tests;
|
|
|
|
|
2019-11-19 23:06:07 +08:00
|
|
|
use App\Services\AirlineService;
|
|
|
|
|
|
|
|
class AirlineTest extends TestCase
|
|
|
|
{
|
2020-05-04 06:23:46 +08:00
|
|
|
/** @var AirlineService */
|
2019-11-19 23:06:07 +08:00
|
|
|
protected $airlineSvc;
|
|
|
|
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
$this->addData('base');
|
|
|
|
|
|
|
|
$this->airlineSvc = app(AirlineService::class);
|
|
|
|
}
|
|
|
|
|
2020-05-04 06:23:46 +08:00
|
|
|
public function testAddAirline()
|
|
|
|
{
|
2020-05-23 23:43:29 +08:00
|
|
|
$attrs = factory(\App\Models\Airline::class)->make([
|
2020-05-04 06:23:46 +08:00
|
|
|
'iata' => '',
|
|
|
|
])->toArray();
|
|
|
|
|
|
|
|
$airline = $this->airlineSvc->createAirline($attrs);
|
|
|
|
$this->assertNotNull($airline);
|
|
|
|
|
|
|
|
// Add another airline, also blank IATA
|
2020-05-23 23:43:29 +08:00
|
|
|
$attrs = factory(\App\Models\Airline::class)->make([
|
2020-05-04 06:23:46 +08:00
|
|
|
'iata' => '',
|
|
|
|
])->toArray();
|
|
|
|
$airline = $this->airlineSvc->createAirline($attrs);
|
|
|
|
$this->assertNotNull($airline);
|
|
|
|
}
|
|
|
|
|
2019-11-19 23:06:07 +08:00
|
|
|
/**
|
|
|
|
* Try deleting an airline which has flights/other assets that exist
|
|
|
|
*/
|
|
|
|
public function testDeleteAirlineWithFlight()
|
|
|
|
{
|
2020-05-23 23:43:29 +08:00
|
|
|
$airline = factory(\App\Models\Airline::class)->create();
|
|
|
|
factory(\App\Models\Flight::class)->create([
|
2019-11-19 23:06:07 +08:00
|
|
|
'airline_id' => $airline->id,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertFalse($this->airlineSvc->canDeleteAirline($airline));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Try deleting an airline with existing PIREPs
|
|
|
|
*/
|
|
|
|
public function testDeleteAirlineWithPirep()
|
|
|
|
{
|
2020-05-23 23:43:29 +08:00
|
|
|
$airline = factory(\App\Models\Airline::class)->create();
|
|
|
|
factory(\App\Models\Pirep::class)->create([
|
2019-11-19 23:06:07 +08:00
|
|
|
'airline_id' => $airline->id,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertFalse($this->airlineSvc->canDeleteAirline($airline));
|
|
|
|
}
|
|
|
|
}
|