add PIREP pre-file and ACARS updates; removing caching from ACARS/Pirep/User repositories; adjust PirepState enum values; add additional columns

This commit is contained in:
Nabeel Shahzad
2017-12-25 15:19:34 -06:00
parent 70b1476e93
commit 3bd97b4d37
41 changed files with 688 additions and 192 deletions

95
tests/AcarsTest.php Normal file
View File

@@ -0,0 +1,95 @@
<?php
use App\Models\Enums\PirepState;
use App\Models\Enums\PirepStatus;
/**
* Test API calls and authentication, etc
*/
class AcarsTest extends TestCase
{
public function setUp()
{
parent::setUp();
$this->addData('base');
}
protected function getPirep($pirep_id)
{
$resp = $this->withHeaders($this->apiHeaders())
->get('/api/pirep/' . $pirep_id);
$resp->assertStatus(200);
return $resp->json();
}
/**
* Post a PIREP into a PREFILE state and post ACARS
*/
public function testAcarsUpdates()
{
$airport = factory(App\Models\Airport::class)->create();
$airline = factory(App\Models\Airline::class)->create();
$aircraft = factory(App\Models\Aircraft::class)->create();
$uri = '/api/pirep/prefile';
$pirep = [
'airline_id' => $airline->id,
'aircraft_id' => $aircraft->id,
'dpt_airport' => $airport->icao,
'arr_airport' => $airport->icao,
'altitude' => 38000,
'planned_flight_time' => 120,
'route' => 'POINTA POINTB',
];
$response = $this->withHeaders($this->apiHeaders())->post($uri, $pirep);
$response->assertStatus(201);
# Get the PIREP ID
$pirep_id = $response->json()['id'];
$this->assertNotNull($pirep_id);
# Check the PIREP state and status
$pirep = $this->getPirep($pirep_id);
$this->assertEquals(PirepState::IN_PROGRESS, $pirep['state']);
$this->assertEquals(PirepStatus::PREFILE, $pirep['status']);
# Post an ACARS update
$uri = '/api/pirep/' . $pirep_id . '/acars';
$acars = factory(App\Models\Acars::class)->make()->toArray();
$response = $this->withHeaders($this->apiHeaders())->post($uri, $acars);
$response->assertStatus(201);
$body = $response->json();
$this->assertNotNull($body['id']);
$this->assertEquals($pirep_id, $body['pirep_id']);
# Make sure PIREP state moved into ENROUTE
$pirep = $this->getPirep($pirep_id);
$this->assertEquals(PirepState::IN_PROGRESS, $pirep['state']);
$this->assertEquals(PirepStatus::ENROUTE, $pirep['status']);
$uri = '/api/pirep/' . $pirep_id . '/acars';
$response = $this->withHeaders($this->apiHeaders())->get($uri);
$response->assertStatus(200);
$body = $response->json();
$this->assertEquals(1, $this->count($body));
$this->assertEquals($pirep_id, $body[0]['pirep_id']);
}
public function testNonExistentPirepGet()
{
$uri = '/api/pirep/DOESNTEXIST/acars';
$response = $this->withHeaders($this->apiHeaders())->get($uri);
$response->assertStatus(404);
}
public function testNonExistentPirepStore()
{
$uri = '/api/pirep/DOESNTEXIST/acars';
$acars = factory(App\Models\Acars::class)->make()->toArray();
$response = $this->withHeaders($this->apiHeaders())->post($uri, $acars);
$response->assertStatus(404);
}
}

View File

@@ -65,6 +65,7 @@ class PIREPTest extends TestCase
# Submit two PIREPs
$pireps = factory(Pirep::class, 2)->create([
'airline_id' => 1,
'user_id' => 1,
# 360min == 6 hours, rank should bump up
'flight_time' => 360,
@@ -87,6 +88,7 @@ class PIREPTest extends TestCase
# it should automatically be accepted
#
$pirep = factory(Pirep::class)->create([
'airline_id' => 1,
'user_id' => 1,
# 120min == 2 hours, currently at 9 hours
# Rank bumps up at 10 hours