2017-12-26 05:19:34 +08:00
|
|
|
<?php
|
|
|
|
|
2020-05-23 23:43:29 +08:00
|
|
|
namespace Tests;
|
|
|
|
|
|
|
|
use App\Exceptions\AircraftNotAtAirport;
|
|
|
|
use App\Exceptions\UserNotAtAirport;
|
|
|
|
use App\Models\Acars;
|
|
|
|
use App\Models\Aircraft;
|
|
|
|
use App\Models\Airline;
|
|
|
|
use App\Models\Airport;
|
2017-12-26 05:19:34 +08:00
|
|
|
use App\Models\Enums\PirepState;
|
|
|
|
use App\Models\Enums\PirepStatus;
|
2020-05-23 23:43:29 +08:00
|
|
|
use App\Models\Fare;
|
|
|
|
use App\Models\Navdata;
|
2019-09-17 01:08:26 +08:00
|
|
|
use App\Models\PirepFare;
|
2020-04-01 13:05:09 +08:00
|
|
|
use App\Models\PirepFieldValue;
|
2020-05-23 23:43:29 +08:00
|
|
|
use App\Models\User;
|
2018-02-21 03:28:53 +08:00
|
|
|
use App\Repositories\SettingRepository;
|
2020-02-23 05:03:01 +08:00
|
|
|
use App\Support\Utils;
|
2020-05-23 23:43:29 +08:00
|
|
|
use function count;
|
|
|
|
use function random_int;
|
2017-12-26 05:19:34 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test API calls and authentication, etc
|
|
|
|
*/
|
|
|
|
class AcarsTest extends TestCase
|
|
|
|
{
|
2018-02-21 03:28:53 +08:00
|
|
|
protected $settingsRepo;
|
|
|
|
|
2019-05-12 23:50:38 +08:00
|
|
|
public function setUp(): void
|
2017-12-26 05:19:34 +08:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
$this->addData('base');
|
2018-02-21 03:28:53 +08:00
|
|
|
|
|
|
|
$this->settingsRepo = app(SettingRepository::class);
|
2017-12-26 05:19:34 +08:00
|
|
|
}
|
|
|
|
|
2018-01-05 09:33:23 +08:00
|
|
|
/**
|
|
|
|
* @param $route
|
|
|
|
* @param $points
|
|
|
|
* @param array $addtl_fields
|
|
|
|
*/
|
2018-08-27 02:50:08 +08:00
|
|
|
protected function allPointsInRoute($route, $points, array $addtl_fields = [])
|
2018-01-05 09:33:23 +08:00
|
|
|
{
|
2018-03-14 23:34:41 +08:00
|
|
|
if (empty($addtl_fields)) {
|
2018-01-05 09:33:23 +08:00
|
|
|
$addtl_fields = [];
|
|
|
|
}
|
|
|
|
|
2018-03-14 23:34:41 +08:00
|
|
|
$fields = array_merge(
|
|
|
|
[
|
|
|
|
'name',
|
|
|
|
'order',
|
|
|
|
'lat',
|
|
|
|
'lon',
|
|
|
|
],
|
|
|
|
$addtl_fields
|
|
|
|
);
|
2018-01-05 09:33:23 +08:00
|
|
|
|
2020-05-23 23:43:29 +08:00
|
|
|
$this->assertCount(count($route), $points);
|
2018-03-14 23:34:41 +08:00
|
|
|
foreach ($route as $idx => $point) {
|
2018-01-07 07:18:30 +08:00
|
|
|
$this->assertHasKeys($points[$idx], $fields);
|
2018-03-14 23:34:41 +08:00
|
|
|
foreach ($fields as $f) {
|
|
|
|
if ($f === 'lat' || $f === 'lon') {
|
2018-01-07 07:15:33 +08:00
|
|
|
continue;
|
2018-01-05 10:19:49 +08:00
|
|
|
}
|
|
|
|
|
2018-01-05 09:33:23 +08:00
|
|
|
$this->assertEquals($point[$f], $points[$idx][$f]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-26 05:19:34 +08:00
|
|
|
protected function getPirep($pirep_id)
|
|
|
|
{
|
2018-03-14 23:34:41 +08:00
|
|
|
$resp = $this->get('/api/pireps/'.$pirep_id);
|
2017-12-26 05:19:34 +08:00
|
|
|
$resp->assertStatus(200);
|
2018-03-14 23:34:41 +08:00
|
|
|
|
2018-02-11 07:34:46 +08:00
|
|
|
return $resp->json()['data'];
|
2017-12-26 05:19:34 +08:00
|
|
|
}
|
|
|
|
|
2018-01-24 01:46:26 +08:00
|
|
|
/**
|
2018-01-24 05:48:30 +08:00
|
|
|
* Test some prefile error conditions
|
2018-01-24 01:46:26 +08:00
|
|
|
*/
|
|
|
|
public function testPrefileErrors()
|
|
|
|
{
|
2022-03-14 23:45:18 +08:00
|
|
|
$this->user = User::factory()->create();
|
2018-01-24 01:46:26 +08:00
|
|
|
|
2022-03-14 23:45:18 +08:00
|
|
|
$airport = Airport::factory()->create();
|
|
|
|
$airline = Airline::factory()->create();
|
|
|
|
$aircraft = Aircraft::factory()->create();
|
2018-01-24 01:46:26 +08:00
|
|
|
|
2018-01-24 05:48:30 +08:00
|
|
|
/**
|
|
|
|
* INVALID AIRLINE_ID FIELD
|
|
|
|
*/
|
2018-01-24 01:46:26 +08:00
|
|
|
$uri = '/api/pireps/prefile';
|
|
|
|
$pirep = [
|
2018-08-27 00:40:04 +08:00
|
|
|
'_airline_id' => $airline->id,
|
|
|
|
'aircraft_id' => $aircraft->id,
|
|
|
|
'dpt_airport_id' => $airport->icao,
|
|
|
|
'arr_airport_id' => $airport->icao,
|
|
|
|
'flight_number' => '6000',
|
|
|
|
'level' => 38000,
|
2018-01-24 01:46:26 +08:00
|
|
|
'planned_flight_time' => 120,
|
2018-08-27 00:40:04 +08:00
|
|
|
'route' => 'POINTA POINTB',
|
2018-01-24 01:46:26 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->post($uri, $pirep);
|
|
|
|
$response->assertStatus(400);
|
|
|
|
}
|
|
|
|
|
2020-08-18 04:44:31 +08:00
|
|
|
public function testPrefileAircraftNotAtAirport()
|
|
|
|
{
|
|
|
|
$this->settingsRepo->store('pilots.only_flights_from_current', false);
|
|
|
|
$this->settingsRepo->store('pireps.restrict_aircraft_to_rank', false);
|
|
|
|
$this->settingsRepo->store('pireps.only_aircraft_at_dpt_airport', true);
|
|
|
|
|
2022-03-14 23:45:18 +08:00
|
|
|
$this->user = User::factory()->create();
|
2020-08-18 04:44:31 +08:00
|
|
|
|
|
|
|
/** @var Airport $airport */
|
2022-03-14 23:45:18 +08:00
|
|
|
$airport = Airport::factory()->create();
|
2020-08-18 04:44:31 +08:00
|
|
|
|
|
|
|
/** @var Airport $airport */
|
2022-03-14 23:45:18 +08:00
|
|
|
$aircraft_airport = Airport::factory()->create();
|
2020-08-18 04:44:31 +08:00
|
|
|
|
|
|
|
/** @var Airline $airline */
|
2022-03-14 23:45:18 +08:00
|
|
|
$airline = Airline::factory()->create();
|
2020-08-18 04:44:31 +08:00
|
|
|
|
|
|
|
/** @var Aircraft $aircraft */
|
2022-03-14 23:45:18 +08:00
|
|
|
$aircraft = Aircraft::factory()->create(['airport_id' => $aircraft_airport->id]);
|
2020-08-18 04:44:31 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* INVALID AIRLINE_ID FIELD
|
|
|
|
*/
|
|
|
|
$uri = '/api/pireps/prefile';
|
|
|
|
$pirep = [
|
|
|
|
'airline_id' => $airline->id,
|
|
|
|
'aircraft_id' => $aircraft->id,
|
|
|
|
'dpt_airport_id' => $airport->icao,
|
|
|
|
'arr_airport_id' => $airport->icao,
|
|
|
|
'flight_number' => '6000',
|
|
|
|
'level' => 38000,
|
|
|
|
'planned_flight_time' => 120,
|
|
|
|
'route' => 'POINTA POINTB',
|
|
|
|
'source_name' => 'Tests',
|
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->post($uri, $pirep);
|
|
|
|
$response->assertStatus(400);
|
|
|
|
$this->assertEquals(
|
|
|
|
'The aircraft is not at the departure airport',
|
|
|
|
$response->json('title')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-12-03 07:27:58 +08:00
|
|
|
public function testBlankAirport()
|
|
|
|
{
|
2022-03-14 23:45:18 +08:00
|
|
|
$this->user = User::factory()->create();
|
2019-12-03 07:27:58 +08:00
|
|
|
|
2022-03-14 23:45:18 +08:00
|
|
|
$airline = Airline::factory()->create();
|
|
|
|
$aircraft = Aircraft::factory()->create();
|
2019-12-03 07:27:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* INVALID AIRLINE_ID FIELD
|
|
|
|
*/
|
|
|
|
$uri = '/api/pireps/prefile';
|
|
|
|
$pirep = [
|
|
|
|
'airline_id' => $airline->id,
|
|
|
|
'aircraft_id' => $aircraft->id,
|
|
|
|
'dpt_airport_id' => null,
|
|
|
|
'arr_airport_id' => null,
|
|
|
|
'flight_number' => '6000',
|
|
|
|
'level' => 38000,
|
|
|
|
'planned_flight_time' => 120,
|
|
|
|
'source_name' => 'ACARSTESTS',
|
|
|
|
'route' => 'POINTA POINTB',
|
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->post($uri, $pirep);
|
|
|
|
$response->assertStatus(400);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
'A departure airport is required, An arrival airport is required',
|
|
|
|
$response->json('details')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-03-31 00:08:53 +08:00
|
|
|
/**
|
|
|
|
* Make sure an error is thrown if the pilot is not at the current airport
|
|
|
|
*/
|
|
|
|
public function testPilotNotAtAirport(): void
|
|
|
|
{
|
|
|
|
$this->settingsRepo->store('pilots.only_flights_from_current', true);
|
|
|
|
$this->settingsRepo->store('pireps.restrict_aircraft_to_rank', false);
|
|
|
|
|
2022-03-14 23:45:18 +08:00
|
|
|
$this->user = User::factory()->create([
|
2018-03-31 00:08:53 +08:00
|
|
|
'curr_airport_id' => 'KJFK',
|
|
|
|
]);
|
|
|
|
|
2022-03-14 23:45:18 +08:00
|
|
|
$airport = Airport::factory()->create();
|
|
|
|
$airline = Airline::factory()->create();
|
|
|
|
$aircraft = Aircraft::factory()->create();
|
2018-03-31 00:08:53 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* INVALID AIRLINE_ID FIELD
|
|
|
|
*/
|
|
|
|
$uri = '/api/pireps/prefile';
|
|
|
|
$pirep = [
|
|
|
|
'airline_id' => $airline->id,
|
|
|
|
'aircraft_id' => $aircraft->id,
|
|
|
|
'dpt_airport_id' => $airport->icao,
|
|
|
|
'arr_airport_id' => $airport->icao,
|
|
|
|
'flight_number' => '6000',
|
|
|
|
'level' => 38000,
|
|
|
|
'planned_flight_time' => 120,
|
|
|
|
'route' => 'POINTA POINTB',
|
|
|
|
'source_name' => 'phpunit',
|
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->post($uri, $pirep);
|
|
|
|
$response->assertStatus(400);
|
|
|
|
$body = $response->json();
|
2020-05-23 23:43:29 +08:00
|
|
|
$this->assertEquals(UserNotAtAirport::MESSAGE, $body['error']['message']);
|
2018-03-31 00:08:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make sure an error is thrown if the pilot is not at the current airport
|
|
|
|
*/
|
|
|
|
public function testAircraftNotAtAirport(): void
|
|
|
|
{
|
|
|
|
$this->settingsRepo->store('pireps.only_aircraft_at_dpt_airport', true);
|
|
|
|
$this->settingsRepo->store('pireps.restrict_aircraft_to_rank', false);
|
|
|
|
$this->settingsRepo->store('pireps.restrict_aircraft_to_rank', false);
|
|
|
|
|
2021-01-25 19:54:17 +08:00
|
|
|
/** @var User user */
|
2022-03-14 23:45:18 +08:00
|
|
|
$this->user = User::factory()->create([
|
2018-03-31 00:08:53 +08:00
|
|
|
'curr_airport_id' => 'KJFK',
|
|
|
|
]);
|
|
|
|
|
2021-01-25 19:54:17 +08:00
|
|
|
/** @var Airport $airport */
|
2022-03-14 23:45:18 +08:00
|
|
|
$airport = Airport::factory()->create();
|
2021-01-25 19:54:17 +08:00
|
|
|
|
|
|
|
/** @var Airline $airline */
|
2022-03-14 23:45:18 +08:00
|
|
|
$airline = Airline::factory()->create();
|
2021-01-25 19:54:17 +08:00
|
|
|
|
|
|
|
/** @var Aircraft $aircraft */
|
2022-03-14 23:45:18 +08:00
|
|
|
$aircraft = Aircraft::factory()->create([
|
2018-08-27 00:40:04 +08:00
|
|
|
'airport_id' => 'KAUS',
|
2018-03-31 00:08:53 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* INVALID AIRLINE_ID FIELD
|
|
|
|
*/
|
|
|
|
$uri = '/api/pireps/prefile';
|
|
|
|
$pirep = [
|
|
|
|
'airline_id' => $airline->id,
|
|
|
|
'aircraft_id' => $aircraft->id,
|
|
|
|
'dpt_airport_id' => $airport->icao,
|
|
|
|
'arr_airport_id' => $airport->icao,
|
|
|
|
'flight_number' => '6000',
|
|
|
|
'level' => 38000,
|
|
|
|
'planned_flight_time' => 120,
|
|
|
|
'route' => 'POINTA POINTB',
|
|
|
|
'source_name' => 'phpunit',
|
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->post($uri, $pirep);
|
|
|
|
$response->assertStatus(400);
|
|
|
|
$body = $response->json();
|
2020-05-23 23:43:29 +08:00
|
|
|
$this->assertEquals(AircraftNotAtAirport::MESSAGE, $body['error']['message']);
|
2018-03-31 00:08:53 +08:00
|
|
|
}
|
|
|
|
|
2017-12-26 05:19:34 +08:00
|
|
|
/**
|
|
|
|
* Post a PIREP into a PREFILE state and post ACARS
|
|
|
|
*/
|
2018-03-14 23:34:41 +08:00
|
|
|
public function testPrefileAndUpdates()
|
2017-12-26 05:19:34 +08:00
|
|
|
{
|
2018-02-21 02:59:49 +08:00
|
|
|
$subfleet = $this->createSubfleetWithAircraft(2);
|
|
|
|
$rank = $this->createRank(10, [$subfleet['subfleet']->id]);
|
|
|
|
|
2022-03-14 23:45:18 +08:00
|
|
|
/** @var Fare $fare */
|
|
|
|
$fare = Fare::factory()->create();
|
|
|
|
|
|
|
|
$this->user = User::factory()->create(
|
2018-03-14 23:34:41 +08:00
|
|
|
[
|
|
|
|
'rank_id' => $rank->id,
|
|
|
|
]
|
|
|
|
);
|
2018-01-05 11:05:26 +08:00
|
|
|
|
2022-03-14 23:45:18 +08:00
|
|
|
/** @var Airport $airport */
|
|
|
|
$airport = Airport::factory()->create();
|
|
|
|
|
|
|
|
/** @var Airline $airline */
|
|
|
|
$airline = Airline::factory()->create();
|
|
|
|
|
|
|
|
/** @var Aircraft $aircraft */
|
2018-02-21 02:59:49 +08:00
|
|
|
$aircraft = $subfleet['aircraft']->random();
|
2017-12-26 05:19:34 +08:00
|
|
|
|
2017-12-29 05:02:59 +08:00
|
|
|
$uri = '/api/pireps/prefile';
|
2017-12-26 05:19:34 +08:00
|
|
|
$pirep = [
|
2018-08-27 00:40:04 +08:00
|
|
|
'airline_id' => $airline->id,
|
|
|
|
'aircraft_id' => $aircraft->id,
|
|
|
|
'dpt_airport_id' => $airport->icao,
|
|
|
|
'arr_airport_id' => $airport->icao,
|
|
|
|
'flight_number' => '6000',
|
|
|
|
'level' => 38000,
|
|
|
|
'planned_distance' => 400,
|
2017-12-26 05:19:34 +08:00
|
|
|
'planned_flight_time' => 120,
|
2018-08-27 00:40:04 +08:00
|
|
|
'route' => 'POINTA POINTB',
|
|
|
|
'source_name' => 'UnitTest',
|
|
|
|
'fields' => [
|
2018-02-07 03:59:40 +08:00
|
|
|
'custom_field' => 'custom_value',
|
2018-03-14 23:34:41 +08:00
|
|
|
],
|
|
|
|
'fares' => [
|
|
|
|
[
|
2018-08-27 00:40:04 +08:00
|
|
|
'id' => $fare->id,
|
2018-03-14 23:34:41 +08:00
|
|
|
'count' => $fare->capacity,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->post($uri, $pirep);
|
2020-04-01 13:05:09 +08:00
|
|
|
$response->assertStatus(200);
|
2018-03-14 23:34:41 +08:00
|
|
|
$pirep = $response->json('data');
|
|
|
|
|
2022-03-14 23:45:18 +08:00
|
|
|
$this->assertEquals(400, $pirep['planned_distance']['nmi']);
|
|
|
|
$this->assertEquals(460.31, $pirep['planned_distance']['mi']);
|
|
|
|
$this->assertEquals(740.8, $pirep['planned_distance']['km']);
|
|
|
|
$this->assertEquals(740800, $pirep['planned_distance']['m']);
|
|
|
|
|
|
|
|
// Are date times in UTC?
|
|
|
|
$this->assertTrue(str_ends_with($pirep['submitted_at'], 'Z'));
|
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// See that the fields and fares were set
|
2019-09-17 01:08:26 +08:00
|
|
|
$fares = PirepFare::where('pirep_id', $pirep['id'])->get();
|
2018-03-14 23:34:41 +08:00
|
|
|
$this->assertCount(1, $fares);
|
|
|
|
$saved_fare = $fares->first();
|
|
|
|
|
|
|
|
$this->assertEquals($fare->id, $saved_fare['fare_id']);
|
|
|
|
$this->assertEquals($fare->capacity, $saved_fare['count']);
|
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// Check saved fields
|
2020-04-01 13:05:09 +08:00
|
|
|
$saved_fields = PirepFieldValue::where('pirep_id', $pirep['id'])->get();
|
2018-03-14 23:34:41 +08:00
|
|
|
$this->assertCount(1, $saved_fields);
|
|
|
|
$field = $saved_fields->first();
|
|
|
|
|
|
|
|
$this->assertEquals('custom_field', $field['name']);
|
|
|
|
$this->assertEquals('custom_value', $field['value']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Try to update fields
|
|
|
|
*/
|
|
|
|
$uri = '/api/pireps/'.$pirep['id'].'/update';
|
|
|
|
$update = [
|
|
|
|
'fares' => [
|
|
|
|
[
|
2018-08-27 00:40:04 +08:00
|
|
|
'id' => $fare->id,
|
2018-03-14 23:34:41 +08:00
|
|
|
'count' => $fare->capacity,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->post($uri, $update);
|
2019-09-17 01:08:26 +08:00
|
|
|
$response->assertOk();
|
2018-03-14 23:34:41 +08:00
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// Make sure there are no duplicates
|
2019-09-17 01:08:26 +08:00
|
|
|
$fares = PirepFare::where('pirep_id', $pirep['id'])->get();
|
2018-03-14 23:34:41 +08:00
|
|
|
$this->assertCount(1, $fares);
|
|
|
|
$saved_fare = $fares->first();
|
|
|
|
|
|
|
|
$this->assertEquals($fare->id, $saved_fare['fare_id']);
|
|
|
|
$this->assertEquals($fare->capacity, $saved_fare['count']);
|
2019-09-17 01:08:26 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Try cancelling the PIREP now
|
|
|
|
*/
|
|
|
|
$uri = '/api/pireps/'.$pirep['id'].'/cancel';
|
|
|
|
$response = $this->put($uri, []);
|
|
|
|
$response->assertOk();
|
|
|
|
|
|
|
|
// Read it
|
|
|
|
$uri = '/api/pireps/'.$pirep['id'];
|
|
|
|
$response = $this->get($uri);
|
|
|
|
$response->assertOk();
|
|
|
|
$body = $response->json('data');
|
|
|
|
|
|
|
|
$this->assertEquals($body['state'], PirepState::CANCELLED);
|
2018-03-14 23:34:41 +08:00
|
|
|
}
|
|
|
|
|
2019-12-03 07:27:58 +08:00
|
|
|
public function testPrefileAndInvalidUpdates()
|
|
|
|
{
|
|
|
|
$subfleet = $this->createSubfleetWithAircraft(2);
|
|
|
|
$rank = $this->createRank(10, [$subfleet['subfleet']->id]);
|
|
|
|
|
2022-03-14 23:45:18 +08:00
|
|
|
$this->user = User::factory()->create([
|
2019-12-03 07:27:58 +08:00
|
|
|
'rank_id' => $rank->id,
|
|
|
|
]);
|
|
|
|
|
2022-03-14 23:45:18 +08:00
|
|
|
$airport = Airport::factory()->create();
|
|
|
|
$airline = Airline::factory()->create();
|
2019-12-03 07:27:58 +08:00
|
|
|
$aircraft = $subfleet['aircraft']->random();
|
|
|
|
|
|
|
|
$uri = '/api/pireps/prefile';
|
|
|
|
$pirep = [
|
|
|
|
'airline_id' => $airline->id,
|
|
|
|
'aircraft_id' => $aircraft->id,
|
|
|
|
'dpt_airport_id' => $airport->icao,
|
|
|
|
'arr_airport_id' => $airport->icao,
|
|
|
|
'flight_number' => '6000',
|
|
|
|
'level' => 38000,
|
|
|
|
'planned_distance' => 400,
|
|
|
|
'planned_flight_time' => 120,
|
|
|
|
'route' => 'POINTA POINTB',
|
|
|
|
'source_name' => 'UnitTest',
|
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->post($uri, $pirep);
|
2020-04-01 13:05:09 +08:00
|
|
|
$response->assertStatus(200);
|
2019-12-03 07:27:58 +08:00
|
|
|
$pirep = $response->json('data');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Try to update fields
|
|
|
|
*/
|
|
|
|
$uri = '/api/pireps/'.$pirep['id'].'/update';
|
|
|
|
$update = [
|
|
|
|
'dpt_airport_id' => '',
|
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->post($uri, $update);
|
|
|
|
$response->assertStatus(400);
|
|
|
|
$detail = $response->json('details');
|
|
|
|
|
|
|
|
$this->assertEquals('A departure airport is required', $detail);
|
|
|
|
}
|
|
|
|
|
2018-03-14 23:34:41 +08:00
|
|
|
/**
|
|
|
|
* Post a PIREP into a PREFILE state and post ACARS
|
2021-04-23 22:33:13 +08:00
|
|
|
*
|
|
|
|
* @throws \Exception
|
2018-03-14 23:34:41 +08:00
|
|
|
*/
|
|
|
|
public function testAcarsUpdates()
|
|
|
|
{
|
|
|
|
$subfleet = $this->createSubfleetWithAircraft(2);
|
|
|
|
$rank = $this->createRank(10, [$subfleet['subfleet']->id]);
|
|
|
|
|
2021-04-23 22:33:13 +08:00
|
|
|
/** @var User user */
|
2022-03-14 23:45:18 +08:00
|
|
|
$this->user = User::factory()->create([
|
2021-04-23 22:33:13 +08:00
|
|
|
'rank_id' => $rank->id,
|
|
|
|
]);
|
2018-03-14 23:34:41 +08:00
|
|
|
|
2021-04-23 22:33:13 +08:00
|
|
|
/** @var Airport $airport */
|
2022-03-14 23:45:18 +08:00
|
|
|
$airport = Airport::factory()->create();
|
2021-04-23 22:33:13 +08:00
|
|
|
|
|
|
|
/** @var Airline $airline */
|
2022-03-14 23:45:18 +08:00
|
|
|
$airline = Airline::factory()->create();
|
2021-04-23 22:33:13 +08:00
|
|
|
|
|
|
|
/** @var Aircraft $aircraft */
|
2018-03-14 23:34:41 +08:00
|
|
|
$aircraft = $subfleet['aircraft']->random();
|
|
|
|
|
|
|
|
$uri = '/api/pireps/prefile';
|
2019-07-16 03:14:40 +08:00
|
|
|
$pirep_create = [
|
2018-08-27 00:40:04 +08:00
|
|
|
'airline_id' => $airline->id,
|
|
|
|
'aircraft_id' => $aircraft->id,
|
|
|
|
'dpt_airport_id' => $airport->icao,
|
|
|
|
'arr_airport_id' => $airport->icao,
|
|
|
|
'flight_number' => '6000',
|
|
|
|
'level' => 38000,
|
|
|
|
'planned_distance' => 400,
|
2018-03-14 23:34:41 +08:00
|
|
|
'planned_flight_time' => 120,
|
2021-06-04 22:51:59 +08:00
|
|
|
'status' => PirepStatus::BOARDING,
|
2018-08-27 00:40:04 +08:00
|
|
|
'route' => 'POINTA POINTB',
|
|
|
|
'source_name' => 'AcarsTest::testAcarsUpdates',
|
|
|
|
'fields' => [
|
2018-03-14 23:34:41 +08:00
|
|
|
'custom_field' => 'custom_value',
|
|
|
|
],
|
2017-12-26 05:19:34 +08:00
|
|
|
];
|
|
|
|
|
2019-07-16 03:14:40 +08:00
|
|
|
$response = $this->post($uri, $pirep_create);
|
2020-04-01 13:05:09 +08:00
|
|
|
$response->assertStatus(200);
|
2017-12-26 05:19:34 +08:00
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// Get the PIREP ID
|
2018-01-05 11:21:51 +08:00
|
|
|
$body = $response->json();
|
2018-02-11 07:34:46 +08:00
|
|
|
$pirep_id = $body['data']['id'];
|
2018-01-05 11:21:51 +08:00
|
|
|
|
2020-04-01 13:05:09 +08:00
|
|
|
$this->assertHasKeys($body['data'], ['airline', 'arr_airport', 'dpt_airport']);
|
2017-12-26 05:19:34 +08:00
|
|
|
$this->assertNotNull($pirep_id);
|
2018-02-11 07:34:46 +08:00
|
|
|
$this->assertEquals($body['data']['user_id'], $this->user->id);
|
2017-12-26 05:19:34 +08:00
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// Check the PIREP state and status
|
2017-12-26 05:19:34 +08:00
|
|
|
$pirep = $this->getPirep($pirep_id);
|
|
|
|
$this->assertEquals(PirepState::IN_PROGRESS, $pirep['state']);
|
2018-04-02 09:18:12 +08:00
|
|
|
$this->assertEquals(PirepStatus::INITIATED, $pirep['status']);
|
2017-12-26 05:19:34 +08:00
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
/*
|
2018-02-07 03:59:40 +08:00
|
|
|
* Check the fields
|
|
|
|
*/
|
|
|
|
$this->assertHasKeys($pirep, ['fields']);
|
2018-05-10 01:45:24 +08:00
|
|
|
$this->assertEquals('custom_value', $pirep['fields']['custom_field']);
|
2019-07-16 03:14:40 +08:00
|
|
|
$this->assertEquals($pirep_create['planned_distance'], $pirep['planned_distance']['nmi']);
|
2018-02-11 12:49:08 +08:00
|
|
|
$this->assertHasKeys($pirep['planned_distance'], ['mi', 'nmi', 'km']);
|
2018-02-11 12:30:42 +08:00
|
|
|
|
2018-02-07 03:59:40 +08:00
|
|
|
/**
|
|
|
|
* Update the custom field
|
|
|
|
*/
|
2018-03-14 23:34:41 +08:00
|
|
|
$uri = '/api/pireps/'.$pirep_id.'/update';
|
2018-05-10 01:45:24 +08:00
|
|
|
$this->post($uri, [
|
2020-03-30 01:33:14 +08:00
|
|
|
'flight_time' => 60,
|
2021-06-04 22:51:59 +08:00
|
|
|
'distance' => 20,
|
|
|
|
'status' => PirepStatus::AIRBORNE,
|
2020-03-30 01:33:14 +08:00
|
|
|
'fields' => [
|
2018-05-10 01:45:24 +08:00
|
|
|
'custom_field' => 'custom_value_changed',
|
|
|
|
],
|
|
|
|
]);
|
2018-02-07 03:59:40 +08:00
|
|
|
|
|
|
|
$pirep = $this->getPirep($pirep_id);
|
2018-05-10 01:45:24 +08:00
|
|
|
$this->assertEquals('custom_value_changed', $pirep['fields']['custom_field']);
|
2018-02-07 03:59:40 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add some position updates
|
|
|
|
*/
|
2018-03-14 23:34:41 +08:00
|
|
|
$uri = '/api/pireps/'.$pirep_id.'/acars/position';
|
2018-01-05 09:33:23 +08:00
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// Test missing positions field
|
|
|
|
// Post an ACARS update
|
2018-01-05 09:33:23 +08:00
|
|
|
$update = [];
|
2018-01-07 02:07:22 +08:00
|
|
|
$response = $this->post($uri, $update);
|
2018-01-05 09:33:23 +08:00
|
|
|
$response->assertStatus(400);
|
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// Post an ACARS update
|
2022-03-14 23:45:18 +08:00
|
|
|
$acars = Acars::factory()->make(['pirep_id' => $pirep_id])->toArray();
|
2018-05-04 04:36:26 +08:00
|
|
|
$acars = $this->transformData($acars);
|
2018-01-05 10:08:22 +08:00
|
|
|
|
2018-01-05 09:33:23 +08:00
|
|
|
$update = ['positions' => [$acars]];
|
2018-01-07 02:07:22 +08:00
|
|
|
$response = $this->post($uri, $update);
|
2018-01-05 10:08:22 +08:00
|
|
|
$response->assertStatus(200)->assertJson(['count' => 1]);
|
2017-12-26 05:19:34 +08:00
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// Read that if the ACARS record posted
|
2022-03-14 23:45:18 +08:00
|
|
|
$response = $this->get($uri);
|
|
|
|
$acars_data = $response->json('data')[0];
|
2018-01-29 01:21:31 +08:00
|
|
|
$this->assertEquals(round($acars['lat'], 2), round($acars_data['lat'], 2));
|
|
|
|
$this->assertEquals(round($acars['lon'], 2), round($acars_data['lon'], 2));
|
2018-01-29 01:12:13 +08:00
|
|
|
$this->assertEquals($acars['log'], $acars_data['log']);
|
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// Make sure PIREP state moved into ENROUTE
|
2017-12-26 05:19:34 +08:00
|
|
|
$pirep = $this->getPirep($pirep_id);
|
|
|
|
$this->assertEquals(PirepState::IN_PROGRESS, $pirep['state']);
|
2018-04-02 09:18:12 +08:00
|
|
|
$this->assertEquals(PirepStatus::AIRBORNE, $pirep['status']);
|
2017-12-26 05:19:34 +08:00
|
|
|
|
2018-01-07 02:07:22 +08:00
|
|
|
$response = $this->get($uri);
|
2017-12-26 05:19:34 +08:00
|
|
|
$response->assertStatus(200);
|
2018-02-11 07:34:46 +08:00
|
|
|
$body = $response->json()['data'];
|
2018-01-05 09:33:23 +08:00
|
|
|
|
|
|
|
$this->assertNotNull($body);
|
|
|
|
$this->assertCount(1, $body);
|
2018-01-05 10:16:29 +08:00
|
|
|
$this->assertEquals(round($acars['lat'], 2), round($body[0]['lat'], 2));
|
|
|
|
$this->assertEquals(round($acars['lon'], 2), round($body[0]['lon'], 2));
|
2018-01-24 01:46:26 +08:00
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// Update fields standalone
|
|
|
|
$uri = '/api/pireps/'.$pirep_id.'/fields';
|
2018-05-10 01:45:24 +08:00
|
|
|
$response = $this->post($uri, [
|
|
|
|
'fields' => [
|
|
|
|
'Departure Gate' => 'G26',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
$body = $response->json('data');
|
|
|
|
$this->assertEquals('G26', $body['Departure Gate']);
|
|
|
|
|
2020-03-30 01:33:14 +08:00
|
|
|
/*
|
|
|
|
* Get the live flights and make sure all the fields we want are there
|
|
|
|
*/
|
|
|
|
$uri = '/api/acars';
|
|
|
|
$response = $this->get($uri);
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
2020-03-30 03:35:40 +08:00
|
|
|
$body = collect($response->json('data'));
|
|
|
|
$body = $body->firstWhere('id', $pirep['id']);
|
2020-03-30 01:33:14 +08:00
|
|
|
|
|
|
|
$this->assertNotEmpty($body['user']['name']);
|
|
|
|
$this->assertNotEmpty($body['user']['avatar']);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* File the PIREP
|
|
|
|
*/
|
|
|
|
|
2018-01-24 01:46:26 +08:00
|
|
|
$uri = '/api/pireps/'.$pirep_id.'/file';
|
|
|
|
$response = $this->post($uri, []);
|
2018-02-11 06:10:19 +08:00
|
|
|
$response->assertStatus(400); // missing field
|
2018-01-24 01:46:26 +08:00
|
|
|
|
|
|
|
$response = $this->post($uri, ['flight_time' => '1:30']);
|
|
|
|
$response->assertStatus(400); // invalid flight time
|
|
|
|
|
2018-05-10 01:45:24 +08:00
|
|
|
$response = $this->post($uri, [
|
|
|
|
'flight_time' => 130,
|
2018-08-27 00:40:04 +08:00
|
|
|
'fuel_used' => 8000.19,
|
|
|
|
'distance' => 400,
|
2018-05-10 01:45:24 +08:00
|
|
|
]);
|
2018-01-31 02:06:46 +08:00
|
|
|
|
2018-01-29 01:12:13 +08:00
|
|
|
$response->assertStatus(200);
|
2018-02-11 07:34:46 +08:00
|
|
|
$body = $response->json();
|
2018-01-24 11:40:34 +08:00
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// Add a comment
|
2018-01-24 11:40:34 +08:00
|
|
|
$uri = '/api/pireps/'.$pirep_id.'/comments';
|
|
|
|
$response = $this->post($uri, ['comment' => 'A comment']);
|
|
|
|
$response->assertStatus(201);
|
|
|
|
|
|
|
|
$response = $this->get($uri);
|
|
|
|
$response->assertStatus(200);
|
|
|
|
$comments = $response->json();
|
|
|
|
|
|
|
|
$this->assertCount(1, $comments);
|
2018-01-05 09:33:23 +08:00
|
|
|
}
|
|
|
|
|
2018-04-05 02:03:10 +08:00
|
|
|
/**
|
|
|
|
* Post a PIREP into a PREFILE state and post ACARS
|
|
|
|
*/
|
|
|
|
public function testFilePirepApi(): void
|
|
|
|
{
|
|
|
|
$subfleet = $this->createSubfleetWithAircraft(2);
|
|
|
|
$rank = $this->createRank(10, [$subfleet['subfleet']->id]);
|
|
|
|
|
2022-03-14 23:45:18 +08:00
|
|
|
$this->user = User::factory()->create([
|
2018-04-05 02:03:10 +08:00
|
|
|
'rank_id' => $rank->id,
|
|
|
|
]);
|
|
|
|
|
2021-05-03 22:00:10 +08:00
|
|
|
/** @var Airport $airport */
|
2022-03-14 23:45:18 +08:00
|
|
|
$airport = Airport::factory()->create();
|
2021-05-03 22:00:10 +08:00
|
|
|
|
|
|
|
/** @var Airline $airline */
|
2022-03-14 23:45:18 +08:00
|
|
|
$airline = Airline::factory()->create();
|
2021-05-03 22:00:10 +08:00
|
|
|
|
|
|
|
/** @var Aircraft $aircraft */
|
2018-04-05 02:03:10 +08:00
|
|
|
$aircraft = $subfleet['aircraft']->random();
|
|
|
|
|
|
|
|
$uri = '/api/pireps/prefile';
|
|
|
|
$pirep = [
|
2018-08-27 00:40:04 +08:00
|
|
|
'airline_id' => $airline->id,
|
|
|
|
'aircraft_id' => $aircraft->id,
|
|
|
|
'dpt_airport_id' => $airport->icao,
|
|
|
|
'arr_airport_id' => $airport->icao,
|
|
|
|
'flight_number' => '6000',
|
|
|
|
'level' => 38000,
|
|
|
|
'source_name' => 'AcarsTest::testFilePirepApi',
|
2018-04-05 02:03:10 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->post($uri, $pirep);
|
2020-04-01 13:05:09 +08:00
|
|
|
$response->assertStatus(200);
|
2018-04-05 02:03:10 +08:00
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// Get the PIREP ID
|
2018-04-05 02:03:10 +08:00
|
|
|
$body = $response->json();
|
|
|
|
$pirep_id = $body['data']['id'];
|
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// File the PIREP now
|
2018-04-05 02:03:10 +08:00
|
|
|
$uri = '/api/pireps/'.$pirep_id.'/file';
|
|
|
|
|
|
|
|
$response = $this->post($uri, [
|
|
|
|
'flight_time' => 130,
|
|
|
|
'fuel_used' => 8000.19,
|
|
|
|
'distance' => 400,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// Check the block_off_time and block_on_time being set
|
2018-04-05 02:03:10 +08:00
|
|
|
$body = $this->get('/api/pireps/'.$pirep_id)->json('data');
|
2021-05-03 22:00:10 +08:00
|
|
|
$this->assertEquals(PirepState::PENDING, $body['state']);
|
2018-04-05 02:03:10 +08:00
|
|
|
$this->assertNotNull($body['block_off_time']);
|
|
|
|
$this->assertNotNull($body['block_on_time']);
|
2021-05-03 22:00:10 +08:00
|
|
|
|
|
|
|
// Try to refile, should be blocked
|
|
|
|
$response = $this->post($uri, [
|
|
|
|
'flight_time' => 130,
|
|
|
|
'fuel_used' => 8000.19,
|
|
|
|
'distance' => 400,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$response->assertStatus(400);
|
2018-04-05 02:03:10 +08:00
|
|
|
}
|
|
|
|
|
2018-02-21 02:59:49 +08:00
|
|
|
/**
|
|
|
|
* Test aircraft is allowed
|
|
|
|
*/
|
|
|
|
public function testAircraftAllowed()
|
|
|
|
{
|
|
|
|
$this->settingsRepo->store('pireps.restrict_aircraft_to_rank', true);
|
|
|
|
|
2022-03-14 23:45:18 +08:00
|
|
|
$airport = Airport::factory()->create();
|
|
|
|
$airline = Airline::factory()->create();
|
2018-02-21 02:59:49 +08:00
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// Add subfleets and aircraft, but also add another set of subfleets
|
2018-02-21 02:59:49 +08:00
|
|
|
$subfleetA = $this->createSubfleetWithAircraft(1);
|
|
|
|
|
|
|
|
// User not allowed aircraft from this subfleet
|
|
|
|
$subfleetB = $this->createSubfleetWithAircraft(1);
|
|
|
|
|
|
|
|
$rank = $this->createRank(10, [$subfleetA['subfleet']->id]);
|
|
|
|
|
2022-03-14 23:45:18 +08:00
|
|
|
$this->user = User::factory()->create(
|
2018-03-14 23:34:41 +08:00
|
|
|
[
|
|
|
|
'rank_id' => $rank->id,
|
|
|
|
]
|
|
|
|
);
|
2018-02-21 02:59:49 +08:00
|
|
|
|
|
|
|
$uri = '/api/pireps/prefile';
|
|
|
|
$pirep = [
|
2018-08-27 00:40:04 +08:00
|
|
|
'airline_id' => $airline->id,
|
|
|
|
'aircraft_id' => $subfleetB['aircraft']->random()->id,
|
|
|
|
'dpt_airport_id' => $airport->icao,
|
|
|
|
'arr_airport_id' => $airport->icao,
|
|
|
|
'flight_number' => '6000',
|
|
|
|
'level' => 38000,
|
2018-02-21 02:59:49 +08:00
|
|
|
'planned_flight_time' => 120,
|
2018-08-27 00:40:04 +08:00
|
|
|
'route' => 'POINTA POINTB',
|
|
|
|
'source_name' => 'Unit test',
|
2018-02-21 02:59:49 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->post($uri, $pirep);
|
|
|
|
$response->assertStatus(400);
|
|
|
|
|
|
|
|
// Try refiling with a valid aircraft
|
|
|
|
$pirep['aircraft_id'] = $subfleetA['aircraft']->random()->id;
|
|
|
|
$response = $this->post($uri, $pirep);
|
2020-04-01 13:05:09 +08:00
|
|
|
$response->assertStatus(200);
|
2018-02-21 03:28:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test aircraft permissions being ignored
|
|
|
|
*/
|
|
|
|
public function testIgnoreAircraftAllowed()
|
|
|
|
{
|
|
|
|
$this->settingsRepo->store('pireps.restrict_aircraft_to_rank', false);
|
|
|
|
|
2022-03-14 23:45:18 +08:00
|
|
|
$airport = Airport::factory()->create();
|
|
|
|
$airline = Airline::factory()->create();
|
2018-02-21 03:28:53 +08:00
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// Add subfleets and aircraft, but also add another set of subfleets
|
2018-02-21 03:28:53 +08:00
|
|
|
$subfleetA = $this->createSubfleetWithAircraft(1);
|
|
|
|
|
|
|
|
// User not allowed aircraft from this subfleet
|
|
|
|
$subfleetB = $this->createSubfleetWithAircraft(1);
|
|
|
|
|
|
|
|
$rank = $this->createRank(10, [$subfleetA['subfleet']->id]);
|
|
|
|
|
2022-03-14 23:45:18 +08:00
|
|
|
$this->user = User::factory()->create(
|
2018-03-14 23:34:41 +08:00
|
|
|
[
|
|
|
|
'rank_id' => $rank->id,
|
|
|
|
]
|
|
|
|
);
|
2018-02-21 03:28:53 +08:00
|
|
|
|
|
|
|
$uri = '/api/pireps/prefile';
|
|
|
|
$pirep = [
|
2018-08-27 00:40:04 +08:00
|
|
|
'airline_id' => $airline->id,
|
|
|
|
'aircraft_id' => $subfleetB['aircraft']->random()->id,
|
|
|
|
'dpt_airport_id' => $airport->icao,
|
|
|
|
'arr_airport_id' => $airport->icao,
|
|
|
|
'flight_number' => '6000',
|
|
|
|
'level' => 38000,
|
2018-02-21 03:28:53 +08:00
|
|
|
'planned_flight_time' => 120,
|
2018-08-27 00:40:04 +08:00
|
|
|
'route' => 'POINTA POINTB',
|
|
|
|
'source_name' => 'Unit test',
|
2018-02-21 03:28:53 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->post($uri, $pirep);
|
2020-04-01 13:05:09 +08:00
|
|
|
$response->assertStatus(200);
|
2018-02-21 02:59:49 +08:00
|
|
|
}
|
|
|
|
|
2018-01-05 09:33:23 +08:00
|
|
|
/**
|
|
|
|
* Test publishing multiple, batched updates
|
2018-08-27 02:51:47 +08:00
|
|
|
*
|
2018-08-27 02:50:08 +08:00
|
|
|
* @throws Exception
|
2018-01-05 09:33:23 +08:00
|
|
|
*/
|
|
|
|
public function testMultipleAcarsPositionUpdates()
|
|
|
|
{
|
2018-02-21 02:59:49 +08:00
|
|
|
$pirep = $this->createPirep()->toArray();
|
2018-01-05 09:33:23 +08:00
|
|
|
|
|
|
|
$uri = '/api/pireps/prefile';
|
2018-01-07 02:07:22 +08:00
|
|
|
$response = $this->post($uri, $pirep);
|
2020-04-01 13:05:09 +08:00
|
|
|
$response->assertStatus(200);
|
2018-01-05 09:33:23 +08:00
|
|
|
|
2018-02-11 07:34:46 +08:00
|
|
|
$pirep_id = $response->json()['data']['id'];
|
2018-01-05 09:33:23 +08:00
|
|
|
|
2018-03-14 23:34:41 +08:00
|
|
|
$uri = '/api/pireps/'.$pirep_id.'/acars/position';
|
2017-12-26 05:19:34 +08:00
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// Post an ACARS update
|
2020-05-23 23:43:29 +08:00
|
|
|
$acars_count = random_int(5, 10);
|
2022-03-14 23:45:18 +08:00
|
|
|
$acars = Acars::factory()->count($acars_count)->make(['id' => ''])
|
2020-02-23 05:03:01 +08:00
|
|
|
->map(function ($point) {
|
|
|
|
$point['id'] = Utils::generateNewId();
|
|
|
|
return $point;
|
|
|
|
})
|
|
|
|
->toArray();
|
2018-01-05 09:33:23 +08:00
|
|
|
|
|
|
|
$update = ['positions' => $acars];
|
2018-01-07 02:07:22 +08:00
|
|
|
$response = $this->post($uri, $update);
|
2018-01-05 10:08:22 +08:00
|
|
|
$response->assertStatus(200)->assertJson(['count' => $acars_count]);
|
2018-01-05 09:33:23 +08:00
|
|
|
|
2020-02-23 05:03:01 +08:00
|
|
|
// Try posting again, should be ignored/not throw any sql errors
|
|
|
|
$response = $this->post($uri, $update);
|
|
|
|
$response->assertStatus(200)->assertJson(['count' => $acars_count]);
|
|
|
|
|
2018-01-07 02:07:22 +08:00
|
|
|
$response = $this->get($uri);
|
2018-02-11 07:34:46 +08:00
|
|
|
$response->assertStatus(200)->assertJsonCount($acars_count, 'data');
|
2017-12-26 05:19:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testNonExistentPirepGet()
|
|
|
|
{
|
2022-03-14 23:45:18 +08:00
|
|
|
$this->user = User::factory()->create();
|
2018-01-05 11:05:26 +08:00
|
|
|
|
2017-12-29 05:02:59 +08:00
|
|
|
$uri = '/api/pireps/DOESNTEXIST/acars';
|
2018-01-07 02:07:22 +08:00
|
|
|
$response = $this->get($uri);
|
2017-12-26 05:19:34 +08:00
|
|
|
$response->assertStatus(404);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNonExistentPirepStore()
|
|
|
|
{
|
2022-03-14 23:45:18 +08:00
|
|
|
$this->user = User::factory()->create();
|
2018-01-05 11:05:26 +08:00
|
|
|
|
2018-01-05 09:33:23 +08:00
|
|
|
$uri = '/api/pireps/DOESNTEXIST/acars/position';
|
2022-03-14 23:45:18 +08:00
|
|
|
$acars = Acars::factory()->make()->toArray();
|
2018-01-07 02:07:22 +08:00
|
|
|
$response = $this->post($uri, $acars);
|
2017-12-26 05:19:34 +08:00
|
|
|
$response->assertStatus(404);
|
|
|
|
}
|
2017-12-26 08:10:24 +08:00
|
|
|
|
|
|
|
public function testAcarsIsoDate()
|
|
|
|
{
|
2018-02-21 02:59:49 +08:00
|
|
|
$pirep = $this->createPirep()->toArray();
|
2018-01-05 09:33:23 +08:00
|
|
|
|
2017-12-29 05:02:59 +08:00
|
|
|
$uri = '/api/pireps/prefile';
|
2018-01-07 02:07:22 +08:00
|
|
|
$response = $this->post($uri, $pirep);
|
2018-02-11 07:34:46 +08:00
|
|
|
$pirep_id = $response->json()['data']['id'];
|
2017-12-26 08:10:24 +08:00
|
|
|
|
|
|
|
$dt = date('c');
|
2018-03-14 23:34:41 +08:00
|
|
|
$uri = '/api/pireps/'.$pirep_id.'/acars/position';
|
2022-03-14 23:45:18 +08:00
|
|
|
$acars = Acars::factory()->make([
|
2020-02-23 05:03:01 +08:00
|
|
|
'sim_time' => $dt,
|
|
|
|
])->toArray();
|
2017-12-26 08:10:24 +08:00
|
|
|
|
2018-01-05 09:33:23 +08:00
|
|
|
$update = ['positions' => [$acars]];
|
2018-01-07 02:07:22 +08:00
|
|
|
$response = $this->post($uri, $update);
|
2018-01-05 09:33:23 +08:00
|
|
|
$response->assertStatus(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the validation
|
|
|
|
*/
|
|
|
|
public function testAcarsInvalidRoutePost()
|
|
|
|
{
|
2018-02-21 02:59:49 +08:00
|
|
|
$pirep = $this->createPirep()->toArray();
|
2018-01-05 09:33:23 +08:00
|
|
|
|
|
|
|
$uri = '/api/pireps/prefile';
|
2018-01-07 02:07:22 +08:00
|
|
|
$response = $this->post($uri, $pirep);
|
2018-02-11 07:34:46 +08:00
|
|
|
$pirep_id = $response->json()['data']['id'];
|
2018-01-05 09:33:23 +08:00
|
|
|
|
2018-08-20 22:20:03 +08:00
|
|
|
// Missing lat/lon
|
2018-01-05 09:33:23 +08:00
|
|
|
$post_route = ['order' => 1, 'name' => 'NAVPOINT'];
|
2018-03-14 23:34:41 +08:00
|
|
|
$uri = '/api/pireps/'.$pirep_id.'/route';
|
2018-01-07 02:07:22 +08:00
|
|
|
$response = $this->post($uri, $post_route);
|
2018-01-05 09:33:23 +08:00
|
|
|
$response->assertStatus(400);
|
|
|
|
|
|
|
|
$post_route = [
|
2020-02-23 05:03:01 +08:00
|
|
|
[
|
|
|
|
'id' => 'NAVPOINT',
|
|
|
|
'order' => 1,
|
|
|
|
'name' => 'NAVPOINT',
|
|
|
|
'lat' => 'notanumber',
|
|
|
|
'lon' => 34.11,
|
|
|
|
],
|
2018-01-05 09:33:23 +08:00
|
|
|
];
|
|
|
|
|
2018-03-14 23:34:41 +08:00
|
|
|
$uri = '/api/pireps/'.$pirep_id.'/route';
|
2018-01-07 02:07:22 +08:00
|
|
|
$response = $this->post($uri, $post_route);
|
2018-01-05 09:33:23 +08:00
|
|
|
$response->assertStatus(400);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAcarsLogPost()
|
|
|
|
{
|
2018-02-21 02:59:49 +08:00
|
|
|
$pirep = $this->createPirep()->toArray();
|
2018-01-05 09:33:23 +08:00
|
|
|
|
|
|
|
$uri = '/api/pireps/prefile';
|
2018-01-07 02:07:22 +08:00
|
|
|
$response = $this->post($uri, $pirep);
|
2018-02-11 07:34:46 +08:00
|
|
|
$pirep_id = $response->json()['data']['id'];
|
2018-01-05 09:33:23 +08:00
|
|
|
|
2022-03-14 23:45:18 +08:00
|
|
|
$acars = Acars::factory()->make();
|
2018-01-05 09:33:23 +08:00
|
|
|
$post_log = [
|
2018-01-05 10:08:22 +08:00
|
|
|
'logs' => [
|
2018-03-14 23:34:41 +08:00
|
|
|
['log' => $acars->log],
|
|
|
|
],
|
2018-01-05 09:33:23 +08:00
|
|
|
];
|
|
|
|
|
2018-03-14 23:34:41 +08:00
|
|
|
$uri = '/api/pireps/'.$pirep_id.'/acars/logs';
|
2018-01-31 02:06:46 +08:00
|
|
|
$response = $this->post($uri, $post_log);
|
|
|
|
$response->assertStatus(200);
|
|
|
|
$body = $response->json();
|
|
|
|
|
|
|
|
$this->assertEquals(1, $body['count']);
|
|
|
|
|
2022-03-14 23:45:18 +08:00
|
|
|
$acars = Acars::factory()->make();
|
2018-01-31 02:06:46 +08:00
|
|
|
$post_log = [
|
|
|
|
'events' => [
|
2018-03-14 23:34:41 +08:00
|
|
|
['event' => $acars->log],
|
|
|
|
],
|
2018-01-31 02:06:46 +08:00
|
|
|
];
|
|
|
|
|
2018-03-14 23:34:41 +08:00
|
|
|
$uri = '/api/pireps/'.$pirep_id.'/acars/events';
|
2018-01-07 02:07:22 +08:00
|
|
|
$response = $this->post($uri, $post_log);
|
2018-01-05 10:08:22 +08:00
|
|
|
$response->assertStatus(200);
|
|
|
|
$body = $response->json();
|
|
|
|
|
|
|
|
$this->assertEquals(1, $body['count']);
|
2018-01-05 09:33:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testAcarsRoutePost()
|
|
|
|
{
|
2018-02-21 02:59:49 +08:00
|
|
|
$pirep = $this->createPirep()->toArray();
|
2018-01-05 09:33:23 +08:00
|
|
|
|
|
|
|
$uri = '/api/pireps/prefile';
|
2018-01-07 02:07:22 +08:00
|
|
|
$response = $this->post($uri, $pirep);
|
2018-02-11 07:34:46 +08:00
|
|
|
$pirep_id = $response->json()['data']['id'];
|
2017-12-26 08:10:24 +08:00
|
|
|
|
2018-01-05 09:33:23 +08:00
|
|
|
$order = 1;
|
|
|
|
$post_route = [];
|
2020-05-23 23:43:29 +08:00
|
|
|
$route_count = random_int(2, 10);
|
2018-01-05 09:33:23 +08:00
|
|
|
|
2022-03-14 23:45:18 +08:00
|
|
|
$route = Navdata::factory()->count($route_count)->create();
|
2018-03-14 23:34:41 +08:00
|
|
|
foreach ($route as $position) {
|
2018-01-05 09:33:23 +08:00
|
|
|
$post_route[] = [
|
|
|
|
'order' => $order,
|
2018-08-27 00:40:04 +08:00
|
|
|
'id' => $position->id,
|
|
|
|
'name' => $position->id,
|
|
|
|
'lat' => $position->lat,
|
|
|
|
'lon' => $position->lon,
|
2018-01-05 09:33:23 +08:00
|
|
|
];
|
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
$order++;
|
2018-01-05 09:33:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$uri = '/api/pireps/'.$pirep_id.'/route';
|
2018-01-07 02:07:22 +08:00
|
|
|
$response = $this->post($uri, ['route' => $post_route]);
|
2018-02-11 08:17:38 +08:00
|
|
|
$response->assertStatus(200)->assertJson(['count' => $route_count]);
|
2018-01-05 09:33:23 +08:00
|
|
|
|
2020-02-23 05:03:01 +08:00
|
|
|
// Try double post to ignore SQL update
|
|
|
|
$response = $this->post($uri, ['route' => $post_route]);
|
|
|
|
$response->assertStatus(200)->assertJson(['count' => $route_count]);
|
|
|
|
|
2018-01-05 09:33:23 +08:00
|
|
|
/**
|
|
|
|
* Get
|
|
|
|
*/
|
2018-03-14 23:34:41 +08:00
|
|
|
$uri = '/api/pireps/'.$pirep_id.'/route';
|
2018-01-07 02:07:22 +08:00
|
|
|
$response = $this->get($uri);
|
2018-02-11 08:17:38 +08:00
|
|
|
$response->assertStatus(200)->assertJsonCount($route_count, 'data');
|
|
|
|
|
|
|
|
$body = $response->json()['data'];
|
2018-01-05 09:33:23 +08:00
|
|
|
$this->allPointsInRoute($post_route, $body);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete and then recheck
|
|
|
|
*/
|
2018-03-14 23:34:41 +08:00
|
|
|
$uri = '/api/pireps/'.$pirep_id.'/route';
|
2018-01-07 02:07:22 +08:00
|
|
|
$response = $this->delete($uri);
|
2017-12-26 08:10:24 +08:00
|
|
|
$response->assertStatus(200);
|
|
|
|
|
2018-03-14 23:34:41 +08:00
|
|
|
$uri = '/api/pireps/'.$pirep_id.'/route';
|
2018-01-07 02:07:22 +08:00
|
|
|
$response = $this->get($uri);
|
2018-02-11 08:17:38 +08:00
|
|
|
$response->assertStatus(200)->assertJsonCount(0, 'data');
|
2017-12-26 08:10:24 +08:00
|
|
|
}
|
2018-01-03 04:31:00 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Try to refile the same PIREP
|
|
|
|
*/
|
|
|
|
public function testDuplicatePirep()
|
|
|
|
{
|
2018-02-21 02:59:49 +08:00
|
|
|
$pirep = $this->createPirep()->toArray();
|
2018-01-05 11:05:26 +08:00
|
|
|
|
2018-01-03 04:31:00 +08:00
|
|
|
$uri = '/api/pireps/prefile';
|
2018-01-07 02:07:22 +08:00
|
|
|
$response = $this->post($uri, $pirep);
|
2020-04-01 13:05:09 +08:00
|
|
|
$response->assertStatus(200);
|
2018-02-11 08:17:38 +08:00
|
|
|
$pirep_id = $response->json()['data']['id'];
|
2018-01-03 04:31:00 +08:00
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// try readding
|
2018-01-07 02:07:22 +08:00
|
|
|
$response = $this->post($uri, $pirep);
|
2018-01-03 04:31:00 +08:00
|
|
|
$response->assertStatus(200);
|
2018-02-11 08:17:38 +08:00
|
|
|
$dupe_pirep_id = $response->json()['data']['id'];
|
|
|
|
|
|
|
|
$this->assertEquals($pirep_id, $dupe_pirep_id);
|
2018-01-03 04:31:00 +08:00
|
|
|
}
|
2017-12-26 05:19:34 +08:00
|
|
|
}
|