Skip to content

Commit

Permalink
Added tests for case when there is no search results
Browse files Browse the repository at this point in the history
  • Loading branch information
zakhenry committed Aug 21, 2015
1 parent ff7c2fd commit b8ccc5c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
16 changes: 15 additions & 1 deletion api/tests/integration/EntityTest.php
Expand Up @@ -650,7 +650,7 @@ public function testNoInnerLumenUrlDecode()

public function testEntitySearch()
{
TestEntity::deleteIndex();
TestEntity::removeAllFromIndex();

$searchEntity = factory(App\Models\TestEntity::class)->create([
'varchar' => 'searchforthisstring'
Expand All @@ -672,4 +672,18 @@ public function testEntitySearch()

$this->assertEquals($searchEntity->entity_id, $collection[0]->entityId);
}

public function testEntitySearchNoResults()
{

TestEntity::reindex();

sleep(1); //give the elastic search agent time to index

$this->get('/test/entities/pages?q=thisstringwontreturnresults', ['Range'=>'entities=0-9']);

$this->assertResponseStatus(404);
$this->shouldReturnJson();
$this->assertJsonArray();
}
}
21 changes: 21 additions & 0 deletions app/src/common/services/pagination/paginationService.spec.ts
Expand Up @@ -389,6 +389,8 @@ interface mockEntity {

$httpBackend.flush();

expect(results).eventually.to.be.fulfilled;

});

it('should be able to query with an empty string', () => {
Expand All @@ -404,6 +406,25 @@ interface mockEntity {

$httpBackend.flush();

expect(results).eventually.to.be.fulfilled;

});

it('should reset the count when there are no search results', () => {

let paginator = paginationService.getPaginatorInstance('/collection').setCount(3);

$httpBackend.expectGET('/api/collection?q=findnothing', (headers) => {
return headers.Range == 'entities=0-2'
})
.respond(404);

let results = paginator.query('findnothing');

$httpBackend.flush();

expect(results).eventually.to.be.rejectedWith(common.services.pagination.PaginatorException);

});

});
Expand Down

0 comments on commit b8ccc5c

Please sign in to comment.