diff --git a/routes/api.php b/routes/api.php
index 3e489af3d..650b36053 100755
--- a/routes/api.php
+++ b/routes/api.php
@@ -13,8 +13,8 @@
|
*/
-Route::group([], function () {
-
+Route::group([], function ()
+{
Route::match(['get'], 'status', 'BaseController@status');
Route::match(['get'], 'airports/{id}', 'AirportController@get');
@@ -24,4 +24,10 @@
Route::match(['get'], 'flights/{id}', 'FlightController@get');
Route::match(['get'], 'pirep/{id}', 'PirepController@get');
+
+ # This is the info of the user whose token is in use
+ Route::match(['get'], 'user', 'UserController@index');
+ #Route::match(['get'], 'user/bids', 'UserController@index');
+ Route::match(['get'], 'users/{id}', 'UserController@get');
+ Route::match(['get'], 'users/{id}/bids', 'UserController@bids');
});
diff --git a/tests/FlightTest.php b/tests/FlightTest.php
index 42f405134..b4ad1b81d 100644
--- a/tests/FlightTest.php
+++ b/tests/FlightTest.php
@@ -1,5 +1,8 @@
addData('base');
+
+ $this->flightSvc = app(FlightService::class);
}
public function addFlight()
@@ -18,15 +23,22 @@ public function addFlight()
$flight->arr_airport_id = 'KJFK';
$flight->save();
+ # subfleet ID is in the base.yml
+ $flight->subfleets()->syncWithoutDetaching([1]);
+
return $flight->id;
}
public function testGetFlight()
{
$flight_id = $this->addFlight();
- $this->get('/api/flights/'.$flight_id, self::$auth_headers)
- ->assertStatus(200)
- ->assertJson(['dpt_airport_id' => 'KAUS']);
+ $req = $this->get('/api/flights/'.$flight_id, self::$auth_headers);
+ $req->assertStatus(200);
+
+ $body = $req->json();
+ $this->assertEquals($flight_id, $body['id']);
+ $this->assertEquals('KAUS', $body['dpt_airport_id']);
+ $this->assertEquals('KJFK', $body['arr_airport_id']);
$this->get('/api/flights/INVALID', self::$auth_headers)
->assertStatus(404);
@@ -44,4 +56,62 @@ public function testSearchFlight()
$req = $this->get('/api/flights/search?' . $query, self::$auth_headers);
$req->assertStatus(200);
}
+
+ /**
+ * Add/remove a bid, test the API, etc
+ * @throws \App\Services\Exception
+ */
+ public function testBids()
+ {
+ $flight_id = $this->addFlight();
+
+ $user = User::find(1);
+ $flight = Flight::find($flight_id);
+
+ $bid = $this->flightSvc->addBid($flight, $user);
+ $this->assertEquals(1, $bid->user_id);
+ $this->assertEquals($flight_id, $bid->flight_id);
+ $this->assertTrue($flight->has_bid);
+
+ # Refresh
+ $flight = Flight::find($flight_id);
+ $this->assertTrue($flight->has_bid);
+
+ # Query the API and see that the user has the bids
+ # And pull the flight details for the user/bids
+ $req = $this->get('/api/user', self::$auth_headers);
+ $req->assertStatus(200);
+ $body = $req->json();
+ $this->assertEquals(1, sizeof($body['bids']));
+ $this->assertEquals($flight_id, $body['bids'][0]['flight_id']);
+
+ $req = $this->get('/api/users/1/bids', self::$auth_headers);
+
+ $body = $req->json();
+ $req->assertStatus(200);
+ $this->assertEquals($flight_id, $body[0]['id']);
+
+ # Now remove the flight and check API
+
+ $this->flightSvc->removeBid($flight, $user);
+
+ $flight = Flight::find($flight_id);
+ $this->assertFalse($flight->has_bid);
+
+ $user = User::find(1);
+ $bids = $user->bids()->get();
+ $this->assertTrue($bids->isEmpty());
+
+ $req = $this->get('/api/user', self::$auth_headers);
+ $req->assertStatus(200);
+
+ $body = $req->json();
+ $this->assertEquals(0, sizeof($body['bids']));
+
+ $req = $this->get('/api/users/1/bids', self::$auth_headers);
+ $req->assertStatus(200);
+ $body = $req->json();
+
+ $this->assertEquals(0, sizeof($body));
+ }
}
diff --git a/tests/data/base.yml b/tests/data/base.yml
index 4464744c5..c8bf22ba3 100644
--- a/tests/data/base.yml
+++ b/tests/data/base.yml
@@ -13,8 +13,10 @@ users:
name: Admin User
email: admin@phpvms.net
password: admin
- apikey: testapikey
+ api_key: testapikey
airline_id: 1
+ home_airport_id: KAUS
+ curr_airport_id: KAUS
rank_id: 1
created_at: now
updated_at: now
@@ -70,6 +72,11 @@ aircraft:
name: Boeing 777-200
registration: NC20
tail_number: 20
+ - id: 3
+ subfleet_id: 1
+ name: Boeing 747-400-PW
+ registration: PW744
+ tail_number: 207X
fares:
- id: 1
@@ -133,6 +140,6 @@ flights:
- id: 1
airline_id: 1
flight_number: 100
- dpt_airport_id: 1
- arr_airport_id: 2
+ dpt_airport_id: KAUS
+ arr_airport_id: KJFK
route: KAUS KJFK