fix some edge cases
This commit is contained in:
@@ -46,6 +46,7 @@ class AirportController extends Controller
|
||||
|
||||
//add pagination
|
||||
$per_page = $request->input('per_page', 10);
|
||||
$per_page = (empty($per_page)) ? 10 : $per_page;
|
||||
$page = $request->input('page', 1);
|
||||
$paginator = new LengthAwarePaginator(
|
||||
$airportsCollection->forPage($page, $per_page),
|
||||
|
||||
@@ -24,7 +24,7 @@ class FlightController extends Controller
|
||||
* @apiDescription List all defined flights
|
||||
*
|
||||
* @apiParam (query params) {number} [page=1] page to fetch
|
||||
* @apiParam (query param) {number} [per_page=10] number of results to fetch per page
|
||||
* @apiParam (query params) {number} [per_page=10] number of results to fetch per page
|
||||
*
|
||||
* @apiExample {curl} example
|
||||
* curl -i http://localhost:8080/flights?page=1&per_page=10
|
||||
@@ -38,6 +38,7 @@ class FlightController extends Controller
|
||||
|
||||
//add pagination
|
||||
$per_page = $request->input('per_page', 10);
|
||||
$per_page = (empty($per_page)) ? 10 : $per_page;
|
||||
$page = $request->input('page', 1);
|
||||
$paginator = new LengthAwarePaginator(
|
||||
$flightCollection->forPage($page, $per_page),
|
||||
@@ -100,6 +101,6 @@ class FlightController extends Controller
|
||||
$deleted = $flight->delete();
|
||||
}
|
||||
|
||||
return response()->json(null, 204);
|
||||
return response()->json(['message' => "flight $id has been removed"], 200);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class TripController extends Controller
|
||||
* @apiDescription This api returns a paginated list of trips found
|
||||
*
|
||||
* @apiParam (query params) {number} [page=1] page to fetch
|
||||
* @apiParam (query param) {number} [per_page=10] number of results to fetch per page
|
||||
* @apiParam (query params) {number} [per_page=10] number of results to fetch per page
|
||||
*
|
||||
* @apiExample {curl} example
|
||||
* curl -i http://localhost:8080/trips?page=1&per_page=10
|
||||
@@ -48,6 +48,7 @@ class TripController extends Controller
|
||||
|
||||
//add pagination
|
||||
$per_page = $request->input('per_page', 10);
|
||||
$per_page = (empty($per_page)) ? 10 : $per_page;
|
||||
$page = $request->input('page', 1);
|
||||
$paginator = new LengthAwarePaginator(
|
||||
$tripsCollection->forPage($page, $per_page),
|
||||
@@ -96,8 +97,8 @@ class TripController extends Controller
|
||||
* @apiGroup Trips
|
||||
* @apiDescription send a destination to this endpoint to add a flight to the trip
|
||||
*
|
||||
* @apiParam (form data) {string} destination the destination of the new flight
|
||||
* @apiParam (url) {number} id the id of the trip to fetch
|
||||
* @apiParam {string} destination the destination of the new flight
|
||||
* @apiParam {number} id the id of the trip to fetch
|
||||
*
|
||||
* @apiExample {curl} example
|
||||
* curl -i http://localhost:8080/trips/1/flights
|
||||
|
||||
@@ -59,6 +59,20 @@ class AirportsCest
|
||||
$I->assertCount(2, $data->data, json_encode($data));
|
||||
}
|
||||
|
||||
public function listAirportsDoesNotReturn500WhenPerPageIsInvalid(AcceptanceTester $I)
|
||||
{
|
||||
$params = [
|
||||
'page' => 1,
|
||||
'per_page' => ''
|
||||
];
|
||||
|
||||
$I->sendGET($this->uri, $params);
|
||||
$r = $I->grabResponse();
|
||||
|
||||
$I->seeResponseCodeIs(200, $r);
|
||||
$I->seeResponseIsJson();
|
||||
}
|
||||
|
||||
public function getAirportReturnsTripJson(AcceptanceTester $I)
|
||||
{
|
||||
$I->sendGET($this->uri, []);
|
||||
|
||||
@@ -59,6 +59,20 @@ class FlightsCest
|
||||
$I->assertCount(2, $data->data, json_encode($data));
|
||||
}
|
||||
|
||||
public function listFlightsDoesNotReturn500WhenPerPageIsInvalid(AcceptanceTester $I)
|
||||
{
|
||||
$params = [
|
||||
'page' => 1,
|
||||
'per_page' => ''
|
||||
];
|
||||
|
||||
$I->sendGET($this->uri, $params);
|
||||
$r = $I->grabResponse();
|
||||
|
||||
$I->seeResponseCodeIs(200, $r);
|
||||
$I->seeResponseIsJson();
|
||||
}
|
||||
|
||||
public function listFlightsReturns0ItemWhenPageIsBeyondEndOfCollection(AcceptanceTester $I)
|
||||
{
|
||||
$params = [
|
||||
|
||||
@@ -59,6 +59,20 @@ class TripsCest
|
||||
$I->assertCount(2, $data->data, json_encode($data));
|
||||
}
|
||||
|
||||
public function listTripsDoesNotReturn500WhenPerPageIsInvalid(AcceptanceTester $I)
|
||||
{
|
||||
$params = [
|
||||
'page' => 1,
|
||||
'per_page' => ''
|
||||
];
|
||||
|
||||
$I->sendGET($this->uri, $params);
|
||||
$r = $I->grabResponse();
|
||||
|
||||
$I->seeResponseCodeIs(200, $r);
|
||||
$I->seeResponseIsJson();
|
||||
}
|
||||
|
||||
public function getTripReturnsTripJson(AcceptanceTester $I)
|
||||
{
|
||||
$I->sendGET($this->uri, []);
|
||||
|
||||
Reference in New Issue
Block a user