Stricter checks on ACARS API data (#451)
* Stricter checks on ACARS API data * More checks
This commit is contained in:
parent
83821d1e04
commit
b06287da23
@ -10,7 +10,7 @@ class CommentRequest extends FormRequest
|
||||
{
|
||||
$rules = [
|
||||
'comment' => 'required',
|
||||
'created_at' => 'nullable|date',
|
||||
'created_at' => 'sometimes|date',
|
||||
];
|
||||
|
||||
return $rules;
|
||||
|
@ -19,9 +19,9 @@ class EventRequest extends FormRequest
|
||||
$rules = [
|
||||
'events' => 'required|array',
|
||||
'events.*.event' => 'required',
|
||||
'events.*.lat' => 'nullable|numeric',
|
||||
'events.*.lon' => 'nullable|numeric',
|
||||
'events.*.created_at' => 'nullable|date',
|
||||
'events.*.lat' => 'sometimes|numeric',
|
||||
'events.*.lon' => 'sometimes|numeric',
|
||||
'events.*.created_at' => 'sometimes|date',
|
||||
];
|
||||
|
||||
return $rules;
|
||||
|
@ -20,28 +20,28 @@ class FileRequest extends FormRequest
|
||||
'distance' => 'required|numeric',
|
||||
'flight_time' => 'required|integer',
|
||||
'fuel_used' => 'required|numeric',
|
||||
'block_time' => 'nullable|integer',
|
||||
'airline_id' => 'nullable|exists:airlines,id',
|
||||
'aircraft_id' => 'nullable|exists:aircraft,id',
|
||||
'flight_number' => 'nullable',
|
||||
'flight_type' => 'nullable',
|
||||
'dpt_airport_id' => 'nullable',
|
||||
'arr_airport_id' => 'nullable',
|
||||
'route_code' => 'nullable',
|
||||
'route_leg' => 'nullable',
|
||||
'planned_distance' => 'nullable|numeric',
|
||||
'planned_flight_time' => 'nullable|integer',
|
||||
'level' => 'nullable|numeric',
|
||||
'zfw' => 'nullable|numeric',
|
||||
'block_fuel' => 'nullable|numeric',
|
||||
'route' => 'nullable',
|
||||
'notes' => 'nullable',
|
||||
'source_name' => 'nullable',
|
||||
'score' => 'nullable|integer',
|
||||
'landing_rate' => 'nullable|numeric',
|
||||
'block_off_time' => 'nullable|date',
|
||||
'block_on_time' => 'nullable|date',
|
||||
'created_at' => 'nullable|date',
|
||||
'block_time' => 'sometimes|integer',
|
||||
'airline_id' => 'sometimes|exists:airlines,id',
|
||||
'aircraft_id' => 'sometimes|exists:aircraft,id',
|
||||
'flight_number' => 'sometimes',
|
||||
'flight_type' => 'sometimes',
|
||||
'dpt_airport_id' => 'sometimes|size:4',
|
||||
'arr_airport_id' => 'sometimes|size:4',
|
||||
'route_code' => 'sometimes',
|
||||
'route_leg' => 'sometimes',
|
||||
'planned_distance' => 'sometimes|numeric',
|
||||
'planned_flight_time' => 'sometimes|integer',
|
||||
'level' => 'sometimes|numeric',
|
||||
'zfw' => 'sometimes|numeric',
|
||||
'block_fuel' => 'sometimes|numeric',
|
||||
'route' => 'sometimes',
|
||||
'notes' => 'sometimes',
|
||||
'source_name' => 'sometimes',
|
||||
'score' => 'sometimes|integer',
|
||||
'landing_rate' => 'sometimes|numeric',
|
||||
'block_off_time' => 'sometimes|date',
|
||||
'block_on_time' => 'sometimes|date',
|
||||
'created_at' => 'sometimes|date',
|
||||
|
||||
// See if the fare objects are included and formatted properly
|
||||
'fares' => 'nullable|array',
|
||||
|
@ -19,9 +19,9 @@ class LogRequest extends FormRequest
|
||||
$rules = [
|
||||
'logs' => 'required|array',
|
||||
'logs.*.log' => 'required',
|
||||
'logs.*.lat' => 'nullable|numeric',
|
||||
'logs.*.lon' => 'nullable|numeric',
|
||||
'logs.*.created_at' => 'nullable|date',
|
||||
'logs.*.lat' => 'sometimes|numeric',
|
||||
'logs.*.lon' => 'sometimes|numeric',
|
||||
'logs.*.created_at' => 'sometimes|date',
|
||||
];
|
||||
|
||||
return $rules;
|
||||
|
@ -23,18 +23,18 @@ class PositionRequest extends FormRequest
|
||||
'positions' => 'required|array',
|
||||
'positions.*.lat' => 'required|numeric',
|
||||
'positions.*.lon' => 'required|numeric',
|
||||
'positions.*.status' => 'nullable',
|
||||
'positions.*.altitude' => 'nullable|numeric',
|
||||
'positions.*.heading' => 'nullable|numeric|between:0,360',
|
||||
'positions.*.vs' => 'nullable',
|
||||
'positions.*.gs' => 'nullable',
|
||||
'positions.*.transponder' => 'nullable',
|
||||
'positions.*.autopilot' => 'nullable',
|
||||
'positions.*.fuel' => 'nullable|numeric',
|
||||
'positions.*.fuel_flow' => 'nullable|numeric',
|
||||
'positions.*.log' => 'nullable',
|
||||
'positions.*.sim_time' => 'nullable|date',
|
||||
'positions.*.created_at' => 'nullable|date',
|
||||
'positions.*.status' => 'sometimes',
|
||||
'positions.*.altitude' => 'sometimes|numeric',
|
||||
'positions.*.heading' => 'sometimes|numeric|between:0,360',
|
||||
'positions.*.vs' => 'sometimes',
|
||||
'positions.*.gs' => 'sometimes',
|
||||
'positions.*.transponder' => 'sometimes',
|
||||
'positions.*.autopilot' => 'sometimes',
|
||||
'positions.*.fuel' => 'sometimes|numeric',
|
||||
'positions.*.fuel_flow' => 'sometimes|numeric',
|
||||
'positions.*.log' => 'sometimes|nullable',
|
||||
'positions.*.sim_time' => 'sometimes|date',
|
||||
'positions.*.created_at' => 'sometimes|date',
|
||||
];
|
||||
|
||||
return $rules;
|
||||
|
@ -12,29 +12,29 @@ class PrefileRequest extends FormRequest
|
||||
'airline_id' => 'required|exists:airlines,id',
|
||||
'aircraft_id' => 'required|exists:aircraft,id',
|
||||
'flight_number' => 'required',
|
||||
'dpt_airport_id' => 'required',
|
||||
'arr_airport_id' => 'required',
|
||||
'flight_id' => 'nullable',
|
||||
'dpt_airport_id' => 'required|size:4',
|
||||
'arr_airport_id' => 'required|size:4',
|
||||
'flight_id' => 'sometimes|exists:flights,id',
|
||||
'source_name' => 'required',
|
||||
'alt_airport_id' => 'nullable',
|
||||
'status' => 'nullable',
|
||||
'alt_airport_id' => 'sometimes|size:4',
|
||||
'status' => 'sometimes',
|
||||
'level' => 'nullable|numeric',
|
||||
'flight_type' => 'nullable',
|
||||
'route_code' => 'nullable',
|
||||
'route_leg' => 'nullable',
|
||||
'distance' => 'nullable|numeric',
|
||||
'block_time' => 'nullable|integer',
|
||||
'flight_time' => 'nullable|integer',
|
||||
'planned_distance' => 'nullable|numeric',
|
||||
'planned_flight_time' => 'nullable|integer',
|
||||
'zfw' => 'nullable|numeric',
|
||||
'block_fuel' => 'nullable|numeric',
|
||||
'flight_type' => 'sometimes',
|
||||
'route_code' => 'sometimes',
|
||||
'route_leg' => 'sometimes',
|
||||
'distance' => 'sometimes|numeric',
|
||||
'block_time' => 'sometimes|integer',
|
||||
'flight_time' => 'sometimes|integer',
|
||||
'planned_distance' => 'sometimes|numeric',
|
||||
'planned_flight_time' => 'sometimes|integer',
|
||||
'zfw' => 'sometimes|numeric',
|
||||
'block_fuel' => 'sometimes|numeric',
|
||||
'route' => 'nullable',
|
||||
'notes' => 'nullable',
|
||||
'score' => 'nullable|integer',
|
||||
'block_off_time' => 'nullable|date',
|
||||
'block_on_time' => 'nullable|date',
|
||||
'created_at' => 'nullable|date',
|
||||
'score' => 'sometimes|integer',
|
||||
'block_off_time' => 'sometimes|date',
|
||||
'block_on_time' => 'sometimes|date',
|
||||
'created_at' => 'sometimes|date',
|
||||
|
||||
// See if the fare objects are included and formatted properly
|
||||
'fares' => 'nullable|array',
|
||||
|
@ -20,7 +20,7 @@ class RouteRequest extends FormRequest
|
||||
'route' => 'required|array',
|
||||
'route.*.name' => 'required',
|
||||
'route.*.order' => 'required|int',
|
||||
'route.*.nav_type' => 'nullable|int',
|
||||
'route.*.nav_type' => 'sometimes|int',
|
||||
'route.*.lat' => 'required|numeric',
|
||||
'route.*.lon' => 'required|numeric',
|
||||
];
|
||||
|
@ -19,29 +19,29 @@ class UpdateRequest extends FormRequest
|
||||
$rules = [
|
||||
'airline_id' => 'nullable|exists:airlines,id',
|
||||
'aircraft_id' => 'nullable|exists:aircraft,id',
|
||||
'flight_number' => 'nullable',
|
||||
'dpt_airport_id' => 'nullable',
|
||||
'arr_airport_id' => 'nullable',
|
||||
'flight_number' => 'sometimes|required|exists:flights,id',
|
||||
'dpt_airport_id' => 'sometimes|required|size:4',
|
||||
'arr_airport_id' => 'sometimes|required|size:4',
|
||||
'route_code' => 'nullable',
|
||||
'route_leg' => 'nullable',
|
||||
'distance' => 'nullable|numeric',
|
||||
'planned_distance' => 'nullable|numeric',
|
||||
'block_time' => 'nullable|integer',
|
||||
'flight_time' => 'nullable|integer',
|
||||
'distance' => 'sometimes|numeric',
|
||||
'planned_distance' => 'sometimes|numeric',
|
||||
'block_time' => 'sometimes|integer',
|
||||
'flight_time' => 'sometimes|integer',
|
||||
'flight_type' => 'nullable',
|
||||
'planned_flight_time' => 'nullable|integer',
|
||||
'level' => 'nullable|numeric',
|
||||
'zfw' => 'nullable|numeric',
|
||||
'fuel_used' => 'nullable|numeric',
|
||||
'block_fuel' => 'nullable|numeric',
|
||||
'route' => 'nullable',
|
||||
'notes' => 'nullable',
|
||||
'source_name' => 'nullable|max:25',
|
||||
'landing_rate' => 'nullable|numeric',
|
||||
'block_off_time' => 'nullable',
|
||||
'block_on_time' => 'nullable',
|
||||
'created_at' => 'nullable',
|
||||
'status' => 'nullable',
|
||||
'planned_flight_time' => 'sometimes|integer',
|
||||
'level' => 'sometimes|numeric',
|
||||
'zfw' => 'sometimes|numeric',
|
||||
'fuel_used' => 'sometimes|numeric',
|
||||
'block_fuel' => 'sometimes|numeric',
|
||||
'route' => 'sometimes|nullable',
|
||||
'notes' => 'sometimes|nullable',
|
||||
'source_name' => 'sometimes|max:25',
|
||||
'landing_rate' => 'sometimes|numeric',
|
||||
'block_off_time' => 'sometimes|date',
|
||||
'block_on_time' => 'sometimes|date',
|
||||
'created_at' => 'sometimes|date',
|
||||
'status' => 'sometimes',
|
||||
'score' => 'nullable|integer',
|
||||
|
||||
// See if the fare objects are included and formatted properly
|
||||
|
@ -43,6 +43,8 @@ Route::group(['middleware' => ['api.auth']], function () {
|
||||
* ACARS related
|
||||
*/
|
||||
Route::post('pireps/prefile', 'PirepController@prefile');
|
||||
Route::post('pireps/{pirep_id}', 'PirepController@update');
|
||||
Route::patch('pireps/{pirep_id}', 'PirepController@update');
|
||||
Route::post('pireps/{pirep_id}/update', 'PirepController@update');
|
||||
Route::post('pireps/{pirep_id}/file', 'PirepController@file');
|
||||
Route::post('pireps/{pirep_id}/comments', 'PirepController@comments_post');
|
||||
|
@ -66,10 +66,10 @@ class Airport extends Model
|
||||
* Validation rules
|
||||
*/
|
||||
public static $rules = [
|
||||
'icao' => 'required',
|
||||
'iata' => 'nullable',
|
||||
'icao' => 'required|size:4',
|
||||
'iata' => 'sometimes|nullable',
|
||||
'name' => 'required',
|
||||
'location' => 'nullable',
|
||||
'location' => 'sometimes',
|
||||
'lat' => 'required|numeric',
|
||||
'lon' => 'required|numeric',
|
||||
'ground_handling_cost' => 'nullable|numeric',
|
||||
|
@ -93,8 +93,8 @@ class Flight extends Model
|
||||
'flight_number' => 'required',
|
||||
'route_code' => 'nullable',
|
||||
'route_leg' => 'nullable',
|
||||
'dpt_airport_id' => 'required',
|
||||
'arr_airport_id' => 'required',
|
||||
'dpt_airport_id' => 'required|size:4|exists:airports,id',
|
||||
'arr_airport_id' => 'required|size:4|exists:airports,id',
|
||||
'level' => 'nullable',
|
||||
];
|
||||
|
||||
|
@ -92,6 +92,38 @@ class AcarsTest extends TestCase
|
||||
$response->assertStatus(400);
|
||||
}
|
||||
|
||||
public function testBlankAirport()
|
||||
{
|
||||
$this->user = factory(App\Models\User::class)->create();
|
||||
|
||||
$airline = factory(App\Models\Airline::class)->create();
|
||||
$aircraft = factory(App\Models\Aircraft::class)->create();
|
||||
|
||||
/**
|
||||
* 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')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure an error is thrown if the pilot is not at the current airport
|
||||
*/
|
||||
@ -273,6 +305,52 @@ class AcarsTest extends TestCase
|
||||
$this->assertEquals($body['state'], PirepState::CANCELLED);
|
||||
}
|
||||
|
||||
public function testPrefileAndInvalidUpdates()
|
||||
{
|
||||
$subfleet = $this->createSubfleetWithAircraft(2);
|
||||
$rank = $this->createRank(10, [$subfleet['subfleet']->id]);
|
||||
|
||||
$this->user = factory(App\Models\User::class)->create([
|
||||
'rank_id' => $rank->id,
|
||||
]);
|
||||
|
||||
$airport = factory(App\Models\Airport::class)->create();
|
||||
$airline = factory(App\Models\Airline::class)->create();
|
||||
$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);
|
||||
$response->assertStatus(201);
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Post a PIREP into a PREFILE state and post ACARS
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user