8000 [Tests] Improve sorted search test · CodingSeo/laravel-json-api@84a96e5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 84a96e5

Browse files
committed
[Tests] Improve sorted search test
1 parent 5428b03 commit 84a96e5

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/Store/EloquentAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ protected function newQuery()
192192
* @param Builder $query
193193
* @param Collection $includePaths
194194
* the paths for resources that will be included.
195-
* @return array
195+
* @return void
196196
*/
197197
protected function with(Builder $query, Collection $includePaths)
198198
{

tests/Integration/Eloquent/PostsTest.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,25 @@ class PostsTest extends TestCase
1313
*/
1414
protected $resourceType = 'posts';
1515

16-
public function testSearch()
16+
/**
17+
* Test searching with a sort parameter.
18+
*/
19+
public function testSortedSearch()
1720
{
18-
factory(Post::class, 3)->create();
21+
$a = factory(Post::class)->create([
22+
'title' => 'Title A',
23+
]);
24+
25+
$b = factory(Post::class)->create([
26+
'title' => 'Title B',
27+
]);
28+
29+
$response = $this->doSearch(['sort' => '-title']);
30+
$response->assertSearchResponse()->assertContainsOnly(['posts' => [$a->getKey(), $b->getKey()]]);
1931

20-
$this->doSearch(['sort' => '-created-at'])->assertSearchResponse();
32+
$json = $response->decodeResponseJson();
33+
$actual = [array_get($json, 'data.0.id'), array_get($json, 'data.1.id')];
34+
$this->assertEquals([$b->getKey(), $a->getKey()], $actual);
2135
}
2236

2337
/**

00)

0