Add /api/airports with pagination to return all the airports #120

This commit is contained in:
Nabeel Shahzad
2018-01-05 10:23:26 -06:00
parent e04fa2e056
commit e931310dee
6 changed files with 52 additions and 3 deletions

View File

@@ -83,4 +83,26 @@ class ApiTest extends TestCase
->get('/api/airports/UNK')
->assertStatus(404);
}
/**
* Get all the airports, test the pagination
*/
public function testGetAllAirports()
{
$user = factory(App\Models\User::class)->create();
factory(App\Models\Airport::class, 120)->create();
$response = $this->user_get($user, '/api/airports/')
->assertStatus(200)
->assertJsonCount(50, 'data');
$body = $response->json();
$this->assertHasKeys($body, ['data', 'links', 'meta']);
$last_page = $body['meta']['last_page'];
$this->user_get($user, '/api/airports?page='.$last_page)
->assertStatus(200)
->assertJsonCount(20, 'data');
}
}