mirror of
https://github.com/cachethq/cachet.git
synced 2026-03-03 02:27:01 +00:00
Merge pull request #4203 from fiveai/fix-api-search-with-pagination
Fix API search with pagination when specifying page
This commit is contained in:
@@ -34,10 +34,11 @@ trait SearchableTrait
|
||||
return $query;
|
||||
}
|
||||
|
||||
if (!array_intersect(array_keys($search), $this->searchable)) {
|
||||
$allowed_search = array_intersect_key($search, array_flip($this->searchable));
|
||||
if (!$allowed_search) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
return $query->where($search);
|
||||
return $query->where($allowed_search);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,49 @@ class IncidentTest extends AbstractApiTestCase
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testGetIncidentsPaginated()
|
||||
{
|
||||
$incidents = factory('CachetHQ\Cachet\Models\Incident', 3)->create();
|
||||
|
||||
$this->get('/api/v1/incidents?per_page=1&page=1');
|
||||
$this->seeJson(['id' => $incidents[0]->id]);
|
||||
$this->assertResponseOk();
|
||||
|
||||
$this->get('/api/v1/incidents?per_page=1&page=2');
|
||||
$this->seeJson(['id' => $incidents[1]->id]);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testGetIncidentsBySearch()
|
||||
{
|
||||
factory('CachetHQ\Cachet\Models\Incident', 3)->create([
|
||||
'status' => 0,
|
||||
]);
|
||||
|
||||
$incidents = factory('CachetHQ\Cachet\Models\Incident', 2)->create([
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
$this->get('/api/v1/incidents?status=1');
|
||||
$this->seeJson(['id' => $incidents[0]->id]);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testGetIncidentsPaginatedBySearch()
|
||||
{
|
||||
factory('CachetHQ\Cachet\Models\Incident', 3)->create([
|
||||
'status' => 0,
|
||||
]);
|
||||
|
||||
$incidents = factory('CachetHQ\Cachet\Models\Incident', 2)->create([
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
$this->get('/api/v1/incidents?status=1&per_page=1&page=1');
|
||||
$this->seeJson(['id' => $incidents[0]->id]);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testGetInvalidIncident()
|
||||
{
|
||||
$this->get('/api/v1/incidents/0');
|
||||
|
||||
Reference in New Issue
Block a user