Set airport and landing time of aircraft after pirep accept #112

This commit is contained in:
Nabeel Shahzad
2018-01-10 12:39:13 -06:00
parent 2f33c7b6aa
commit dce9723979
5 changed files with 47 additions and 5 deletions

View File

@@ -48,8 +48,10 @@ class PIREPTest extends TestCase
*/
public function testAddPirep()
{
$user = factory(App\Models\User::class)->create();
$route = $this->createNewRoute();
$pirep = factory(App\Models\Pirep::class)->create([
'user_id' => $user->id,
'route' => implode(' ', $route)
]);
@@ -73,6 +75,13 @@ class PIREPTest extends TestCase
$this->assertEquals($new_flight_time, $pirep->pilot->flight_time);
$this->assertEquals($pirep->arr_airport_id, $pirep->pilot->curr_airport_id);
# Check the location of the current aircraft
$this->assertEquals($pirep->aircraft->airport_id, $pirep->arr_airport_id);
# Also check via API:
$this->get('/api/fleet/aircraft/' . $pirep->aircraft_id, [], $user)
->assertJson(['airport_id' => $pirep->arr_airport_id]);
/**
* Now go from ACCEPTED to REJECTED
*/

View File

@@ -111,14 +111,17 @@ abstract class TestCase extends Illuminate\Foundation\Testing\TestCase
* Override the GET call to inject the user API key
* @param string $uri
* @param array $headers
* @param null $user
* @return \Illuminate\Foundation\Testing\TestResponse
*/
public function get($uri, array $headers=[]): \Illuminate\Foundation\Testing\TestResponse
public function get($uri, array $headers=[], $user=null): \Illuminate\Foundation\Testing\TestResponse
{
if(empty($headers)) {
if($this->user !== null) {
$headers = $this->headers($this->user);
}
if($this->user !== null) {
$headers = $this->headers($this->user);
}
if($user !== null) {
$headers['x-api-key'] = $user->api_key;
}
return parent::get($uri, $headers);