Load Simbrief and flight data when getting bids #664 (#665)

This commit is contained in:
Nabeel S
2020-04-15 10:11:06 -04:00
committed by GitHub
parent b1bdd40da7
commit 8e97a7cc5c
3 changed files with 40 additions and 4 deletions

View File

@@ -13,6 +13,19 @@ use Illuminate\Support\Facades\Log;
class BidService extends Service
{
/**
* Get a specific bid for a user
*
* @param $bid_id
*
* @return \App\Models\Bid|\Illuminate\Database\Eloquent\Model|object|null
*/
public function getBid($bid_id)
{
return Bid::with(['flight', 'flight.simbrief'])
->where(['id' => $bid_id])->first();
}
/**
* Find all of the bids for a given user
*
@@ -22,8 +35,8 @@ class BidService extends Service
*/
public function findBidsForUser(User $user)
{
$bids = Bid::where(['user_id' => $user->id])->get();
return $bids;
return Bid::with(['flight', 'flight.simbrief'])
->where(['user_id' => $user->id])->get();
}
/**
@@ -86,7 +99,7 @@ class BidService extends Service
$flight->has_bid = true;
$flight->save();
return $bid;
return $this->getBid($bid->id);
}
/**

View File

@@ -1,5 +1,6 @@
<?php
use App\Exceptions\BidExistsForFlight;
use App\Models\Bid;
use App\Models\Flight;
use App\Models\User;
@@ -136,7 +137,7 @@ class BidTest extends TestCase
$this->bidSvc->addBid($flight, $user1);
// Try adding again, should throw an exception
$this->expectException(\App\Exceptions\BidExistsForFlight::class);
$this->expectException(BidExistsForFlight::class);
$this->bidSvc->addBid($flight, $user2);
}

View File

@@ -9,6 +9,8 @@ use Carbon\Carbon;
class SimBriefTest extends TestCase
{
private static $simbrief_flight_id = 'simbriefflightid';
/**
* Load SimBrief
*
@@ -19,6 +21,7 @@ class SimBriefTest extends TestCase
protected function loadSimBrief($user): SimBrief
{
$flight = factory(App\Models\Flight::class)->create([
'id' => self::$simbrief_flight_id,
'dpt_airport_id' => 'OMAA',
'arr_airport_id' => 'OMDB',
]);
@@ -107,6 +110,25 @@ class SimBriefTest extends TestCase
$this->assertEquals('FlightPlan', $xml->attributes()->Type);
}
/**
* Make sure the user's bids have the Simbrief data show up
*/
public function testUserBidSimbrief()
{
$this->user = factory(App\Models\User::class)->create();
$this->loadSimBrief($this->user);
// Find the flight
$uri = '/api/user/bids';
$data = ['flight_id' => self::$simbrief_flight_id];
$body = $this->put($uri, $data);
$body = $body->json('data');
// Make sure Simbrief is there
$this->assertNotNull($body['flight']['simbrief']['id']);
}
public function testAttachToPirep()
{
$user = factory(App\Models\User::class)->create();