2017-06-20 00:30:39 +08:00
|
|
|
<?php
|
|
|
|
|
2018-03-23 10:21:35 +08:00
|
|
|
use App\Models\Enums\Days;
|
2017-12-13 06:58:27 +08:00
|
|
|
use App\Models\Flight;
|
|
|
|
use App\Models\User;
|
2018-02-10 04:26:14 +08:00
|
|
|
use App\Repositories\SettingRepository;
|
2019-08-27 00:32:46 +08:00
|
|
|
use App\Services\AirportService;
|
2018-02-10 04:26:14 +08:00
|
|
|
use App\Services\FlightService;
|
2017-06-20 00:30:39 +08:00
|
|
|
|
|
|
|
class FlightTest extends TestCase
|
|
|
|
{
|
2018-08-27 00:40:04 +08:00
|
|
|
protected $flightSvc;
|
|
|
|
protected $settingsRepo;
|
2018-02-10 04:26:14 +08:00
|
|
|
|
2019-05-12 23:50:38 +08:00
|
|
|
public function setUp(): void
|
2017-06-20 00:30:39 +08:00
|
|
|
{
|
|
|
|
parent::setUp();
|
2017-08-15 12:36:49 +08:00
|
|
|
$this->addData('base');
|
2017-12-13 06:58:27 +08:00
|
|
|
|
|
|
|
$this->flightSvc = app(FlightService::class);
|
2018-02-10 04:26:14 +08:00
|
|
|
$this->settingsRepo = app(SettingRepository::class);
|
2017-06-20 00:30:39 +08:00
|
|
|
}
|
|
|
|
|
2018-02-10 03:20:35 +08:00
|
|
|
public function addFlight($user)
|
2017-06-20 00:30:39 +08:00
|
|
|
{
|
2018-02-10 03:20:35 +08:00
|
|
|
$flight = factory(App\Models\Flight::class)->create([
|
2018-08-27 00:40:04 +08:00
|
|
|
'airline_id' => $user->airline_id,
|
2018-02-10 03:20:35 +08:00
|
|
|
]);
|
|
|
|
|
2017-12-13 11:50:55 +08:00
|
|
|
$flight->subfleets()->syncWithoutDetaching([
|
2018-02-10 03:20:35 +08:00
|
|
|
factory(App\Models\Subfleet::class)->create([
|
2018-08-27 00:40:04 +08:00
|
|
|
'airline_id' => $user->airline_id,
|
|
|
|
])->id,
|
2017-12-13 11:50:55 +08:00
|
|
|
]);
|
2017-12-13 06:58:27 +08:00
|
|
|
|
2017-12-13 11:50:55 +08:00
|
|
|
return $flight;
|
2017-08-15 12:36:49 +08:00
|
|
|
}
|
|
|
|
|
2018-04-26 00:53:32 +08:00
|
|
|
/**
|
|
|
|
* Test adding a flight and also if there are duplicates
|
|
|
|
*/
|
|
|
|
public function testDuplicateFlight()
|
|
|
|
{
|
|
|
|
$this->user = factory(App\Models\User::class)->create();
|
|
|
|
$flight = $this->addFlight($this->user);
|
|
|
|
|
|
|
|
// first flight shouldn't be a duplicate
|
|
|
|
$this->assertFalse($this->flightSvc->isFlightDuplicate($flight));
|
|
|
|
|
|
|
|
$flight_dupe = new Flight([
|
|
|
|
'airline_id' => $flight->airline_id,
|
|
|
|
'flight_number' => $flight->flight_number,
|
|
|
|
'route_code' => $flight->route_code,
|
|
|
|
'route_leg' => $flight->route_leg,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertTrue($this->flightSvc->isFlightDuplicate($flight_dupe));
|
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// same flight but diff airline shouldn't be a dupe
|
2018-04-26 00:53:32 +08:00
|
|
|
$new_airline = factory(App\Models\Airline::class)->create();
|
|
|
|
$flight_dupe = new Flight([
|
|
|
|
'airline_id' => $new_airline->airline_id,
|
|
|
|
'flight_number' => $flight->flight_number,
|
|
|
|
'route_code' => $flight->route_code,
|
|
|
|
'route_leg' => $flight->route_leg,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertFalse($this->flightSvc->isFlightDuplicate($flight_dupe));
|
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// add another flight with a code
|
2018-04-26 00:53:32 +08:00
|
|
|
$flight_leg = factory(App\Models\Flight::class)->create([
|
|
|
|
'airline_id' => $flight->airline_id,
|
|
|
|
'flight_number' => $flight->flight_number,
|
|
|
|
'route_code' => 'A',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertFalse($this->flightSvc->isFlightDuplicate($flight_leg));
|
|
|
|
|
|
|
|
// Add both a route and leg
|
|
|
|
$flight_leg = factory(App\Models\Flight::class)->create([
|
|
|
|
'airline_id' => $flight->airline_id,
|
|
|
|
'flight_number' => $flight->flight_number,
|
|
|
|
'route_code' => 'A',
|
|
|
|
'route_leg' => 1,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertFalse($this->flightSvc->isFlightDuplicate($flight_leg));
|
|
|
|
}
|
|
|
|
|
2017-11-23 01:52:02 +08:00
|
|
|
public function testGetFlight()
|
2017-08-15 12:36:49 +08:00
|
|
|
{
|
2018-02-10 03:20:35 +08:00
|
|
|
$this->user = factory(App\Models\User::class)->create();
|
|
|
|
$flight = $this->addFlight($this->user);
|
2017-12-13 11:50:55 +08:00
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
$req = $this->get('/api/flights/'.$flight->id);
|
2017-12-13 06:58:27 +08:00
|
|
|
$req->assertStatus(200);
|
|
|
|
|
2018-02-11 07:34:46 +08:00
|
|
|
$body = $req->json()['data'];
|
2017-12-13 11:50:55 +08:00
|
|
|
$this->assertEquals($flight->id, $body['id']);
|
|
|
|
$this->assertEquals($flight->dpt_airport_id, $body['dpt_airport_id']);
|
|
|
|
$this->assertEquals($flight->arr_airport_id, $body['arr_airport_id']);
|
2017-12-12 21:25:11 +08:00
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// Distance conversion
|
2018-02-11 11:16:32 +08:00
|
|
|
$this->assertHasKeys($body['distance'], ['mi', 'nmi', 'km']);
|
|
|
|
|
2017-12-12 21:25:11 +08:00
|
|
|
$this->get('/api/flights/INVALID', self::$auth_headers)
|
|
|
|
->assertStatus(404);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Search based on all different criteria
|
|
|
|
*/
|
|
|
|
public function testSearchFlight()
|
|
|
|
{
|
2018-02-10 03:20:35 +08:00
|
|
|
$this->user = factory(App\Models\User::class)->create();
|
|
|
|
$flight = $this->addFlight($this->user);
|
2017-12-12 21:25:11 +08:00
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// search specifically for a flight ID
|
|
|
|
$query = 'flight_id='.$flight->id;
|
|
|
|
$req = $this->get('/api/flights/search?'.$query);
|
2017-12-12 21:25:11 +08:00
|
|
|
$req->assertStatus(200);
|
2017-06-20 00:30:39 +08:00
|
|
|
}
|
2017-12-13 06:58:27 +08:00
|
|
|
|
2018-02-21 02:06:52 +08:00
|
|
|
/**
|
|
|
|
* Get the flight's route
|
2018-08-27 02:51:47 +08:00
|
|
|
*
|
2018-08-27 02:50:08 +08:00
|
|
|
* @throws Exception
|
2018-02-21 02:06:52 +08:00
|
|
|
*/
|
|
|
|
public function testFlightRoute()
|
|
|
|
{
|
|
|
|
$this->user = factory(App\Models\User::class)->create();
|
|
|
|
$flight = $this->addFlight($this->user);
|
|
|
|
|
|
|
|
$route_count = random_int(4, 6);
|
|
|
|
$route = factory(App\Models\Navdata::class, $route_count)->create();
|
|
|
|
$route_text = implode(' ', $route->pluck('id')->toArray());
|
|
|
|
|
|
|
|
$flight->route = $route_text;
|
|
|
|
$flight->save();
|
|
|
|
|
|
|
|
$res = $this->get('/api/flights/'.$flight->id.'/route');
|
|
|
|
$res->assertStatus(200);
|
|
|
|
$body = $res->json();
|
|
|
|
|
|
|
|
$this->assertCount($route_count, $body['data']);
|
|
|
|
|
|
|
|
$first_point = $body['data'][0];
|
|
|
|
$this->assertEquals($first_point['id'], $route[0]->id);
|
|
|
|
$this->assertEquals($first_point['name'], $route[0]->name);
|
|
|
|
$this->assertEquals($first_point['type']['type'], $route[0]->type);
|
|
|
|
$this->assertEquals(
|
|
|
|
$first_point['type']['name'],
|
|
|
|
\App\Models\Enums\NavaidType::label($route[0]->type)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-01-07 05:21:21 +08:00
|
|
|
/**
|
|
|
|
* Find all of the flights
|
|
|
|
*/
|
|
|
|
public function testFindAllFlights()
|
|
|
|
{
|
2018-02-10 03:20:35 +08:00
|
|
|
$this->user = factory(App\Models\User::class)->create();
|
2018-02-10 05:42:37 +08:00
|
|
|
factory(App\Models\Flight::class, 20)->create([
|
2018-08-27 00:40:04 +08:00
|
|
|
'airline_id' => $this->user->airline_id,
|
2018-02-10 03:20:35 +08:00
|
|
|
]);
|
|
|
|
|
2019-09-13 23:21:40 +08:00
|
|
|
$res = $this->get('/api/flights?limit=10');
|
2018-01-07 05:21:21 +08:00
|
|
|
|
|
|
|
$body = $res->json();
|
2018-01-22 02:51:42 +08:00
|
|
|
$this->assertEquals(2, $body['meta']['last_page']);
|
2018-01-07 05:21:21 +08:00
|
|
|
|
2019-09-13 23:21:40 +08:00
|
|
|
$res = $this->get('/api/flights?page=2&limit=5');
|
2018-02-10 05:42:37 +08:00
|
|
|
$res->assertJsonCount(5, 'data');
|
2018-01-07 05:21:21 +08:00
|
|
|
}
|
|
|
|
|
2018-03-23 10:21:35 +08:00
|
|
|
/**
|
|
|
|
* Test the bitmasks that they work for setting the day of week and
|
|
|
|
* then retrieving by searching on those
|
|
|
|
*/
|
|
|
|
public function testFindDaysOfWeek(): void
|
|
|
|
{
|
|
|
|
$this->user = factory(App\Models\User::class)->create();
|
|
|
|
factory(App\Models\Flight::class, 20)->create([
|
2018-08-27 00:40:04 +08:00
|
|
|
'airline_id' => $this->user->airline_id,
|
2018-03-23 10:21:35 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
$saved_flight = factory(App\Models\Flight::class)->create([
|
|
|
|
'airline_id' => $this->user->airline_id,
|
2018-08-27 00:40:04 +08:00
|
|
|
'days' => Days::getDaysMask([
|
2018-03-23 10:21:35 +08:00
|
|
|
Days::SUNDAY,
|
2018-08-27 00:40:04 +08:00
|
|
|
Days::THURSDAY,
|
|
|
|
]),
|
2018-03-23 10:21:35 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
$flight = Flight::findByDays([Days::SUNDAY])->first();
|
|
|
|
$this->assertTrue($flight->on_day(Days::SUNDAY));
|
|
|
|
$this->assertTrue($flight->on_day(Days::THURSDAY));
|
|
|
|
$this->assertFalse($flight->on_day(Days::MONDAY));
|
|
|
|
$this->assertEquals($saved_flight->id, $flight->id);
|
|
|
|
|
|
|
|
$flight = Flight::findByDays([Days::SUNDAY, Days::THURSDAY])->first();
|
|
|
|
$this->assertEquals($saved_flight->id, $flight->id);
|
|
|
|
|
|
|
|
$flight = Flight::findByDays([Days::WEDNESDAY, Days::THURSDAY])->first();
|
|
|
|
$this->assertNull($flight);
|
2018-04-13 05:12:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make sure that flights are marked as inactive when they're out of the start/end
|
|
|
|
* zones. also make sure that flights with a specific day of the week are only
|
|
|
|
* active on those days
|
|
|
|
*/
|
|
|
|
public function testDayOfWeekActive(): void
|
|
|
|
{
|
|
|
|
$this->user = factory(App\Models\User::class)->create();
|
|
|
|
|
|
|
|
// Set it to Monday or Tuesday, depending on what today is
|
2018-04-17 05:46:51 +08:00
|
|
|
if (date('N') === '1') { // today is a monday
|
2018-04-13 05:12:32 +08:00
|
|
|
$days = Days::getDaysMask([Days::TUESDAY]);
|
|
|
|
} else {
|
|
|
|
$days = Days::getDaysMask([Days::MONDAY]);
|
|
|
|
}
|
|
|
|
|
|
|
|
factory(App\Models\Flight::class, 5)->create();
|
|
|
|
$flight = factory(App\Models\Flight::class)->create([
|
|
|
|
'days' => $days,
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Run the event that will enable/disable flights
|
|
|
|
$event = new \App\Events\CronNightly();
|
|
|
|
(new \App\Cron\Nightly\SetActiveFlights())->handle($event);
|
|
|
|
|
|
|
|
$res = $this->get('/api/flights');
|
|
|
|
$body = $res->json('data');
|
|
|
|
|
|
|
|
$flights = collect($body)->where('id', $flight->id)->first();
|
|
|
|
$this->assertNull($flights);
|
|
|
|
}
|
|
|
|
|
2018-07-25 00:21:52 +08:00
|
|
|
public function testDayOfWeekTests(): void
|
|
|
|
{
|
|
|
|
$mask = 127;
|
|
|
|
$this->assertTrue(Days::in($mask, Days::$isoDayMap[1]));
|
|
|
|
$this->assertTrue(Days::in($mask, Days::$isoDayMap[2]));
|
|
|
|
$this->assertTrue(Days::in($mask, Days::$isoDayMap[3]));
|
|
|
|
$this->assertTrue(Days::in($mask, Days::$isoDayMap[4]));
|
|
|
|
$this->assertTrue(Days::in($mask, Days::$isoDayMap[5]));
|
|
|
|
$this->assertTrue(Days::in($mask, Days::$isoDayMap[6]));
|
|
|
|
$this->assertTrue(Days::in($mask, Days::$isoDayMap[7]));
|
|
|
|
|
|
|
|
$mask = 125;
|
|
|
|
$this->assertTrue(Days::in($mask, Days::$isoDayMap[1]));
|
|
|
|
$this->assertFalse(Days::in($mask, Days::$isoDayMap[2]));
|
|
|
|
$this->assertTrue(Days::in($mask, Days::$isoDayMap[3]));
|
|
|
|
$this->assertTrue(Days::in($mask, Days::$isoDayMap[4]));
|
|
|
|
$this->assertTrue(Days::in($mask, Days::$isoDayMap[5]));
|
|
|
|
$this->assertTrue(Days::in($mask, Days::$isoDayMap[6]));
|
|
|
|
$this->assertTrue(Days::in($mask, Days::$isoDayMap[7]));
|
|
|
|
}
|
|
|
|
|
2018-04-13 05:12:32 +08:00
|
|
|
public function testStartEndDate(): void
|
|
|
|
{
|
|
|
|
$this->user = factory(App\Models\User::class)->create();
|
|
|
|
|
|
|
|
factory(App\Models\Flight::class, 5)->create();
|
|
|
|
$flight = factory(App\Models\Flight::class)->create([
|
|
|
|
'start_date' => Carbon\Carbon::now('UTC')->subDays(1),
|
|
|
|
'end_date' => Carbon\Carbon::now('UTC')->addDays(1),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$flight_not_active = factory(App\Models\Flight::class)->create([
|
|
|
|
'start_date' => Carbon\Carbon::now('UTC')->subDays(10),
|
|
|
|
'end_date' => Carbon\Carbon::now('UTC')->subDays(2),
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Run the event that will enable/disable flights
|
|
|
|
$event = new \App\Events\CronNightly();
|
|
|
|
(new \App\Cron\Nightly\SetActiveFlights())->handle($event);
|
|
|
|
|
|
|
|
$res = $this->get('/api/flights');
|
|
|
|
$body = $res->json('data');
|
|
|
|
|
|
|
|
$flights = collect($body)->where('id', $flight->id)->first();
|
|
|
|
$this->assertNotNull($flights);
|
|
|
|
|
|
|
|
$flights = collect($body)->where('id', $flight_not_active->id)->first();
|
|
|
|
$this->assertNull($flights);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testStartEndDateDayOfWeek(): void
|
|
|
|
{
|
|
|
|
$this->user = factory(App\Models\User::class)->create();
|
|
|
|
|
|
|
|
// Set it to Monday or Tuesday, depending on what today is
|
2018-04-17 05:57:22 +08:00
|
|
|
if (date('N') === '1') { // today is a monday
|
2018-04-13 05:12:32 +08:00
|
|
|
$days = Days::getDaysMask([Days::TUESDAY]);
|
|
|
|
} else {
|
|
|
|
$days = Days::getDaysMask([Days::MONDAY]);
|
|
|
|
}
|
|
|
|
|
|
|
|
factory(App\Models\Flight::class, 5)->create();
|
|
|
|
$flight = factory(App\Models\Flight::class)->create([
|
|
|
|
'start_date' => Carbon\Carbon::now('UTC')->subDays(1),
|
|
|
|
'end_date' => Carbon\Carbon::now('UTC')->addDays(1),
|
|
|
|
'days' => Days::$isoDayMap[date('N')],
|
|
|
|
]);
|
|
|
|
|
2018-07-13 20:43:27 +08:00
|
|
|
// Not active because of days of week not today
|
2018-04-13 05:12:32 +08:00
|
|
|
$flight_not_active = factory(App\Models\Flight::class)->create([
|
|
|
|
'start_date' => Carbon\Carbon::now('UTC')->subDays(1),
|
|
|
|
'end_date' => Carbon\Carbon::now('UTC')->addDays(1),
|
|
|
|
'days' => $days,
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Run the event that will enable/disable flights
|
|
|
|
$event = new \App\Events\CronNightly();
|
|
|
|
(new \App\Cron\Nightly\SetActiveFlights())->handle($event);
|
|
|
|
|
|
|
|
$res = $this->get('/api/flights');
|
|
|
|
$body = $res->json('data');
|
|
|
|
|
|
|
|
$flights = collect($body)->where('id', $flight->id)->first();
|
|
|
|
$this->assertNotNull($flights);
|
|
|
|
|
|
|
|
$flights = collect($body)->where('id', $flight_not_active->id)->first();
|
|
|
|
$this->assertNull($flights);
|
2018-03-23 10:21:35 +08:00
|
|
|
}
|
|
|
|
|
2018-01-07 02:07:22 +08:00
|
|
|
public function testFlightSearchApi()
|
|
|
|
{
|
2018-02-10 03:20:35 +08:00
|
|
|
$this->user = factory(App\Models\User::class)->create();
|
2018-03-18 07:45:18 +08:00
|
|
|
$flights = factory(App\Models\Flight::class, 10)->create([
|
2018-08-27 00:40:04 +08:00
|
|
|
'airline_id' => $this->user->airline_id,
|
2018-02-10 03:20:35 +08:00
|
|
|
]);
|
|
|
|
|
2018-01-07 02:07:22 +08:00
|
|
|
$flight = $flights->random();
|
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
$query = 'flight_number='.$flight->flight_number;
|
|
|
|
$req = $this->get('/api/flights/search?'.$query);
|
2018-01-07 02:07:22 +08:00
|
|
|
$body = $req->json();
|
|
|
|
|
|
|
|
$this->assertEquals($flight->id, $body['data'][0]['id']);
|
|
|
|
}
|
|
|
|
|
2020-01-10 22:41:32 +08:00
|
|
|
public function testFlightSearchApiDepartureAirport()
|
|
|
|
{
|
|
|
|
$this->user = factory(App\Models\User::class)->create();
|
|
|
|
factory(App\Models\Flight::class, 10)->create([
|
|
|
|
'airline_id' => $this->user->airline_id,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$flight = factory(App\Models\Flight::class)->create([
|
|
|
|
'airline_id' => $this->user->airline_id,
|
|
|
|
'dpt_airport_id' => 'KAUS',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$query = 'dpt_airport_id=kaus';
|
|
|
|
$req = $this->get('/api/flights/search?'.$query);
|
|
|
|
$body = $req->json();
|
|
|
|
|
|
|
|
$this->assertCount(1, $body['data']);
|
|
|
|
$this->assertEquals($flight->id, $body['data'][0]['id']);
|
|
|
|
}
|
|
|
|
|
2019-05-11 05:03:04 +08:00
|
|
|
public function testFlightSearchApiDistance()
|
|
|
|
{
|
|
|
|
$total_flights = 10;
|
|
|
|
$this->user = factory(App\Models\User::class)->create();
|
|
|
|
$flights = factory(App\Models\Flight::class, $total_flights)->create([
|
|
|
|
'airline_id' => $this->user->airline_id,
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Max distance generated in factory is 1000, so set a random flight
|
|
|
|
// and try to find it again through the search
|
|
|
|
|
|
|
|
$flight = $flights->random();
|
|
|
|
$flight->distance = 1500;
|
|
|
|
$flight->save();
|
|
|
|
|
2019-05-12 00:37:06 +08:00
|
|
|
$distance_gt = 1100;
|
2019-05-11 05:03:04 +08:00
|
|
|
$distance_lt = 1600;
|
|
|
|
|
|
|
|
// look for all of the flights now less than the "factory default" of 1000
|
|
|
|
$query = 'dlt=1000&ignore_restrictions=1';
|
|
|
|
$req = $this->get('/api/flights/search?'.$query);
|
|
|
|
$body = $req->json();
|
|
|
|
$this->assertCount($total_flights - 1, $body['data']);
|
|
|
|
|
|
|
|
// Try using greater than
|
|
|
|
$query = 'dgt='.$distance_gt.'&ignore_restrictions=1';
|
|
|
|
$req = $this->get('/api/flights/search?'.$query);
|
|
|
|
$body = $req->json();
|
2019-05-12 00:37:06 +08:00
|
|
|
|
2019-05-11 05:03:04 +08:00
|
|
|
$this->assertCount(1, $body['data']);
|
|
|
|
$this->assertEquals($flight->id, $body['data'][0]['id']);
|
|
|
|
|
|
|
|
$query = 'dgt='.$distance_gt.'&dlt='.$distance_lt.'&ignore_restrictions=1';
|
|
|
|
$req = $this->get('/api/flights/search?'.$query);
|
|
|
|
$body = $req->json();
|
|
|
|
$this->assertCount(1, $body['data']);
|
|
|
|
$this->assertEquals($flight->id, $body['data'][0]['id']);
|
|
|
|
}
|
|
|
|
|
2018-03-24 03:10:18 +08:00
|
|
|
public function testAddSubfleet()
|
|
|
|
{
|
|
|
|
$subfleet = factory(App\Models\Subfleet::class)->create();
|
|
|
|
$flight = factory(App\Models\Flight::class)->create();
|
|
|
|
|
|
|
|
$fleetSvc = app(App\Services\FleetService::class);
|
|
|
|
$fleetSvc->addSubfleetToFlight($subfleet, $flight);
|
|
|
|
|
|
|
|
$flight->refresh();
|
|
|
|
$found = $flight->subfleets()->get();
|
|
|
|
$this->assertCount(1, $found);
|
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// Make sure it hasn't been added twice
|
2018-03-24 03:10:18 +08:00
|
|
|
$fleetSvc->addSubfleetToFlight($subfleet, $flight);
|
|
|
|
$flight->refresh();
|
|
|
|
$found = $flight->subfleets()->get();
|
|
|
|
$this->assertCount(1, $found);
|
|
|
|
}
|
|
|
|
|
2018-01-01 23:32:04 +08:00
|
|
|
/**
|
|
|
|
* Delete a flight and make sure all the bids are gone
|
|
|
|
*/
|
|
|
|
public function testDeleteFlight()
|
|
|
|
{
|
|
|
|
$user = factory(User::class)->create();
|
|
|
|
|
2018-02-10 03:20:35 +08:00
|
|
|
$flight = $this->addFlight($user);
|
2018-01-01 23:32:04 +08:00
|
|
|
$this->flightSvc->deleteFlight($flight);
|
|
|
|
|
|
|
|
$empty_flight = Flight::find($flight->id);
|
|
|
|
$this->assertNull($empty_flight);
|
|
|
|
}
|
2019-08-27 00:32:46 +08:00
|
|
|
|
|
|
|
public function testAirportDistance()
|
|
|
|
{
|
|
|
|
// KJFK
|
|
|
|
$fromIcao = factory(App\Models\Airport::class)->create([
|
|
|
|
'lat' => 40.6399257,
|
|
|
|
'lon' => -73.7786950,
|
|
|
|
]);
|
|
|
|
|
|
|
|
// KSFO
|
|
|
|
$toIcao = factory(App\Models\Airport::class)->create([
|
|
|
|
'lat' => 37.6188056,
|
|
|
|
'lon' => -122.3754167,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$airportSvc = app(AirportService::class);
|
|
|
|
$distance = $airportSvc->calculateDistance($fromIcao->id, $toIcao->id);
|
|
|
|
$this->assertNotNull($distance);
|
|
|
|
$this->assertEquals(2244.33, $distance['nmi']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAirportDistanceApi()
|
|
|
|
{
|
|
|
|
$user = factory(User::class)->create();
|
|
|
|
$headers = $this->headers($user);
|
|
|
|
|
|
|
|
// KJFK
|
|
|
|
$fromIcao = factory(App\Models\Airport::class)->create([
|
|
|
|
'lat' => 40.6399257,
|
|
|
|
'lon' => -73.7786950,
|
|
|
|
]);
|
|
|
|
|
|
|
|
// KSFO
|
|
|
|
$toIcao = factory(App\Models\Airport::class)->create([
|
|
|
|
'lat' => 37.6188056,
|
|
|
|
'lon' => -122.3754167,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$req = $this->get('/api/airports/'.$fromIcao->id.'/distance/'.$toIcao->id, $headers);
|
|
|
|
$req->assertStatus(200);
|
|
|
|
|
|
|
|
$body = $req->json()['data'];
|
|
|
|
|
|
|
|
$this->assertNotNull($body['distance']);
|
|
|
|
$this->assertEquals(2244.33, $body['distance']['nmi']);
|
|
|
|
}
|
2017-06-20 00:30:39 +08:00
|
|
|
}
|