mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
added test for #332
This commit is contained in:
parent
2d9cdac14c
commit
ab5c5069aa
@ -6,6 +6,7 @@ use App\Http\QueryBuilder\AnimeSearchQueryBuilder;
|
||||
use App\Http\QueryBuilder\MediaSearchQueryBuilder;
|
||||
use App\Testing\ScoutFlush;
|
||||
use App\Testing\SyntheticMongoDbTransaction;
|
||||
use Illuminate\Database\Eloquent\Factories\Sequence;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Tests\TestCase;
|
||||
@ -425,6 +426,49 @@ class AnimeSearchEndpointTest extends TestCase
|
||||
$this->assertCollectionsStrictlyEqual($expectedItems, $actualItems);
|
||||
}
|
||||
|
||||
public function testOrderingByScoreWithKeywordSearch()
|
||||
{
|
||||
// test for issue https://github.com/jikan-me/jikan-rest/issues/332
|
||||
$title = "awesome anime";
|
||||
$items = Anime::factory(3)->state(new Sequence(
|
||||
["score" => 8.05],
|
||||
["score" => 7.15],
|
||||
["score" => 6.51],
|
||||
))->create([
|
||||
"titles" => [
|
||||
[
|
||||
"type" => "Default",
|
||||
"title" => $title
|
||||
]
|
||||
],
|
||||
"title" => $title,
|
||||
"title_english" => $title,
|
||||
"title_japanese" => $title,
|
||||
"title_synonyms" => [$title],
|
||||
]);
|
||||
Anime::factory(3)->state(new Sequence(
|
||||
["score" => 3.05],
|
||||
["score" => 4.15],
|
||||
["score" => 1.51],
|
||||
))->create();
|
||||
|
||||
$content = $this->getJsonResponse([
|
||||
"order_by" => "score",
|
||||
"q" => "awesome",
|
||||
"page" => 1,
|
||||
"sort" => "desc",
|
||||
"limit" => 15
|
||||
]);
|
||||
|
||||
$expectedItems = $items->map(fn($elem) => data_get($elem, "score"));
|
||||
$actualItems = collect($content["data"])->map(fn($elem) => data_get($elem, "score"));
|
||||
|
||||
$this->assertPaginationData(3, 3, 15);
|
||||
$this->assertIsArray($content["data"]);
|
||||
$this->assertCount(3, $content["data"]);
|
||||
$this->assertCollectionsStrictlyEqual($expectedItems, $actualItems);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidRatingParameterProvider
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user