Skip to content

Commit

Permalink
Fix PirepComment response; 201 to 200
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeelio committed Apr 1, 2020
1 parent e8037c7 commit 4424798
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 15 deletions.
12 changes: 11 additions & 1 deletion app/Http/Controllers/Api/PirepController.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,18 @@ protected function updateFares($pirep, Request $request)
*/
public function get($id)
{
$with = [
'acars',
'arr_airport',
'dpt_airport',
'comments',
'flight',
'simbrief',
'user'
];

$pirep = $this->pirepRepo
->with(['acars', 'arr_airport', 'dpt_airport', 'comments', 'flight', 'simbrief', 'user'])
->with($with)
->find($id);

return new PirepResource($pirep);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Resources/Pirep.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function toArray($request)
$res['arr_airport'] = new Airport($this->arr_airport);

$res['position'] = Acars::make($this->whenLoaded('position'));
$res['comments'] = PirepComment::make($this->whenLoaded('comments'));
$res['comments'] = PirepComment::collection($this->whenLoaded('comments'));
$res['user'] = User::make($this->whenLoaded('user'));

$res['flight'] = Flight::make($this->whenLoaded('flight'));
Expand Down
7 changes: 7 additions & 0 deletions app/Http/Resources/PirepComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use App\Contracts\Resource;

/**
* @mixin \App\Models\PirepComment
*/
class PirepComment extends Resource
{
/**
Expand All @@ -15,6 +18,10 @@ class PirepComment extends Resource
*/
public function toArray($request)
{
if (!$this->user) {
return [];
}

$user = $this->user;

return [
Expand Down
6 changes: 4 additions & 2 deletions app/Models/PirepComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
use App\Contracts\Model;

/**
* @property string pirep_id
* @property int user_id
* @property string $pirep_id
* @property int $user_id
* @property Pirep $pirep
* @property User $user
*/
class PirepComment extends Model
{
Expand Down
11 changes: 10 additions & 1 deletion app/Repositories/AcarsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,16 @@ public function forPirep($pirep_id, $type)
*/
public function getPositions($live_time = 0)
{
$q = Pirep::with(['aircraft', 'airline', 'arr_airport', 'dpt_airport', 'position', 'user'])
$with = [
'aircraft',
'airline',
'arr_airport',
'dpt_airport',
'position',
'user'
];

$q = Pirep::with($with)
->where(['state' => PirepState::IN_PROGRESS]);

if ($live_time !== null && $live_time > 0) {
Expand Down
21 changes: 11 additions & 10 deletions tests/AcarsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use App\Models\Enums\PirepState;
use App\Models\Enums\PirepStatus;
use App\Models\PirepFare;
use App\Models\PirepFieldValue;
use App\Repositories\SettingRepository;
use App\Support\Utils;

Expand Down Expand Up @@ -247,7 +248,7 @@ public function testPrefileAndUpdates()
];

$response = $this->post($uri, $pirep);
$response->assertStatus(201);
$response->assertStatus(200);
$pirep = $response->json('data');

// See that the fields and fares were set
Expand All @@ -259,7 +260,7 @@ public function testPrefileAndUpdates()
$this->assertEquals($fare->capacity, $saved_fare['count']);

// Check saved fields
$saved_fields = \App\Models\PirepFieldValue::where('pirep_id', $pirep['id'])->get();
$saved_fields = PirepFieldValue::where('pirep_id', $pirep['id'])->get();
$this->assertCount(1, $saved_fields);
$field = $saved_fields->first();

Expand Down Expand Up @@ -334,7 +335,7 @@ public function testPrefileAndInvalidUpdates()
];

$response = $this->post($uri, $pirep);
$response->assertStatus(201);
$response->assertStatus(200);
$pirep = $response->json('data');

/**
Expand Down Expand Up @@ -388,13 +389,13 @@ public function testAcarsUpdates()
];

$response = $this->post($uri, $pirep_create);
$response->assertStatus(201);
$response->assertStatus(200);

// Get the PIREP ID
$body = $response->json();
$pirep_id = $body['data']['id'];

$this->assertHasKeys($body['data'], ['airline', 'arr_airport', 'dpt_airport', 'position']);
$this->assertHasKeys($body['data'], ['airline', 'arr_airport', 'dpt_airport']);
$this->assertNotNull($pirep_id);
$this->assertEquals($body['data']['user_id'], $this->user->id);

Expand Down Expand Up @@ -550,7 +551,7 @@ public function testFilePirepApi(): void
];

$response = $this->post($uri, $pirep);
$response->assertStatus(201);
$response->assertStatus(200);

// Get the PIREP ID
$body = $response->json();
Expand Down Expand Up @@ -616,7 +617,7 @@ public function testAircraftAllowed()
// Try refiling with a valid aircraft
$pirep['aircraft_id'] = $subfleetA['aircraft']->random()->id;
$response = $this->post($uri, $pirep);
$response->assertStatus(201);
$response->assertStatus(200);
}

/**
Expand Down Expand Up @@ -657,7 +658,7 @@ public function testIgnoreAircraftAllowed()
];

$response = $this->post($uri, $pirep);
$response->assertStatus(201);
$response->assertStatus(200);
}

/**
Expand All @@ -671,7 +672,7 @@ public function testMultipleAcarsPositionUpdates()

$uri = '/api/pireps/prefile';
$response = $this->post($uri, $pirep);
$response->assertStatus(201);
$response->assertStatus(200);

$pirep_id = $response->json()['data']['id'];

Expand Down Expand Up @@ -869,7 +870,7 @@ public function testDuplicatePirep()

$uri = '/api/pireps/prefile';
$response = $this->post($uri, $pirep);
$response->assertStatus(201);
$response->assertStatus(200);
$pirep_id = $response->json()['data']['id'];

// try readding
Expand Down

0 comments on commit 4424798

Please sign in to comment.