* Make sure proper subfleets are returned as part of the user profile #848 * Formatting
This commit is contained in:
@@ -89,10 +89,7 @@ class UserController extends Controller
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
$user = $this->userRepo
|
||||
->with(['airline', 'bids', 'rank'])
|
||||
->find($id);
|
||||
|
||||
$user = $this->userSvc->getUser($id);
|
||||
return new UserResource($user);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ class User extends Resource
|
||||
$res['airline'] = Airline::make($this->whenLoaded('airline'));
|
||||
$res['bids'] = UserBid::collection($this->whenLoaded('bids'));
|
||||
$res['rank'] = Rank::make($this->whenLoaded('rank'));
|
||||
$res['subfleets'] = Subfleet::make($this->whenLoaded('subfleets'));
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
@@ -54,6 +54,26 @@ class UserService extends Service
|
||||
$this->userRepo = $userRepo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the user and return them with all of the data properly attached
|
||||
*
|
||||
* @param $user_id
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function getUser($user_id): User
|
||||
{
|
||||
$user = $this->userRepo
|
||||
->with(['airline', 'bids', 'rank'])
|
||||
->find($user_id);
|
||||
|
||||
// Load the proper subfleets to the rank
|
||||
$user->rank->subfleets = $this->getAllowableSubfleets($user);
|
||||
$user->subfleets = $user->rank->subfleets;
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a pilot. Also attaches the initial roles
|
||||
* required, and then triggers the UserRegistered event
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use App\Models\Aircraft;
|
||||
use App\Models\Subfleet;
|
||||
|
||||
trait TestData
|
||||
@@ -72,7 +73,7 @@ trait TestData
|
||||
$aircraft_count = \random_int(2, 10);
|
||||
}
|
||||
|
||||
$aircraft = factory(\App\Models\Aircraft::class, $aircraft_count)->create([
|
||||
$aircraft = factory(Aircraft::class, $aircraft_count)->create([
|
||||
'subfleet_id' => $subfleet->id,
|
||||
'airport_id' => $airport_id,
|
||||
]);
|
||||
|
||||
@@ -85,6 +85,8 @@ class UserTest extends TestCase
|
||||
/**
|
||||
* Flip the setting for getting all of the user's aircraft restricted
|
||||
* by rank. Make sure that they're all returned
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testGetAllAircraft()
|
||||
{
|
||||
@@ -135,7 +137,7 @@ class UserTest extends TestCase
|
||||
$this->assertEquals($subfleetACalled->fares[0]['capacity'], $overrides['capacity']);
|
||||
|
||||
/**
|
||||
* Check via API
|
||||
* Check via API, but should only show the single subfleet being returned
|
||||
*/
|
||||
$this->settingsRepo->store('pireps.restrict_aircraft_to_rank', true);
|
||||
|
||||
@@ -146,6 +148,18 @@ class UserTest extends TestCase
|
||||
$subfleetAFromApi = collect($body)->firstWhere('id', $subfleetA['subfleet']->id);
|
||||
$this->assertEquals($subfleetAFromApi['fares'][0]['price'], $overrides['price']);
|
||||
$this->assertEquals($subfleetAFromApi['fares'][0]['capacity'], $overrides['capacity']);
|
||||
|
||||
// Read the user's profile and make sure that subfleet C is not part of this
|
||||
// Should only return a single subfleet (subfleet A)
|
||||
$resp = $this->get('/api/user', [], $user);
|
||||
$resp->assertStatus(200);
|
||||
|
||||
$body = $resp->json('data');
|
||||
$subfleets = $body['rank']['subfleets'];
|
||||
|
||||
$this->assertEquals(1, count($subfleets));
|
||||
$this->assertEquals($subfleets[0]['fares'][0]['price'], $overrides['price']);
|
||||
$this->assertEquals($subfleets[0]['fares'][0]['capacity'], $overrides['capacity']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user