diff --git a/app/Services/BidService.php b/app/Services/BidService.php index 9e3e5ef6..c3f84f0b 100644 --- a/app/Services/BidService.php +++ b/app/Services/BidService.php @@ -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); } /** diff --git a/tests/BidTest.php b/tests/BidTest.php index 68e59c5c..bc07ea3f 100644 --- a/tests/BidTest.php +++ b/tests/BidTest.php @@ -1,5 +1,6 @@ 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); } diff --git a/tests/SimBriefTest.php b/tests/SimBriefTest.php index fa39fe19..5b1b3a60 100644 --- a/tests/SimBriefTest.php +++ b/tests/SimBriefTest.php @@ -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();