Major refactoring and cleanup of ACARS/Pirep API

This commit is contained in:
Nabeel Shahzad
2018-01-28 11:12:13 -06:00
parent 77d0d2bcd0
commit 653ff2a104
16 changed files with 387 additions and 231 deletions

View File

@@ -47,7 +47,6 @@ class AcarsTest extends TestCase
protected function getPirep($pirep_id)
{
$this->user = factory(App\Models\User::class)->create();
$resp = $this ->get('/api/pireps/' . $pirep_id);
$resp->assertStatus(200);
return $resp->json();
@@ -116,6 +115,7 @@ class AcarsTest extends TestCase
$this->assertHasKeys($body, ['airline', 'arr_airport', 'dpt_airport', 'position']);
$this->assertNotNull($pirep_id);
$this->assertEquals($body['user_id'], $this->user->id);
# Check the PIREP state and status
$pirep = $this->getPirep($pirep_id);
@@ -131,13 +131,20 @@ class AcarsTest extends TestCase
$response->assertStatus(400);
# Post an ACARS update
$acars = factory(App\Models\Acars::class)->make()->toArray();
unset($acars['id']);
$acars = factory(App\Models\Acars::class)->make([
'id' => null
])->toArray();
$update = ['positions' => [$acars]];
$response = $this->post($uri, $update);
$response->assertStatus(200)->assertJson(['count' => 1]);
# Read that if the ACARS record posted
$acars_data = $this->get($uri)->json()[0];
$this->assertEquals($acars['lat'], $acars_data['lat']);
$this->assertEquals($acars['lon'], $acars_data['lon']);
$this->assertEquals($acars['log'], $acars_data['log']);
# Make sure PIREP state moved into ENROUTE
$pirep = $this->getPirep($pirep_id);
$this->assertEquals(PirepState::IN_PROGRESS, $pirep['state']);
@@ -161,7 +168,7 @@ class AcarsTest extends TestCase
$response->assertStatus(400); // invalid flight time
$response = $this->post($uri, ['flight_time' => '130']);
$response->assertStatus(200); // invalid flight time
$response->assertStatus(200);
# Add a comment
$uri = '/api/pireps/'.$pirep_id.'/comments';