Add /api/airports with pagination to return all the airports #120
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,4 +95,15 @@ abstract class TestCase extends Illuminate\Foundation\Testing\TestCase
|
||||
$this->assertArrayHasKey($key, $obj);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut for a get call with a user
|
||||
* @param \App\Models\User $user
|
||||
* @param string $uri
|
||||
* @return \Illuminate\Foundation\Testing\TestResponse
|
||||
*/
|
||||
public function user_get($user, $uri)
|
||||
{
|
||||
return $this->withHeaders($this->headers($user))->get($uri);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user