Skip to content

Commit

Permalink
Merge pull request #557 from jikan-me/fix-555
Browse files Browse the repository at this point in the history
✅ Fixed bug with season endpoint returning incorrect items when continuing flag specified
  • Loading branch information
pushrbx authored Nov 8, 2024
2 parents 52c030d + 8c6398d commit 53508e8
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 9 deletions.
27 changes: 27 additions & 0 deletions app/Producers.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,33 @@ public function toSearchableArray(): array
];
}

public function getCollectionSchema(): array
{
return [
'name' => $this->searchableAs(),
'fields' => [
[
'name' => '.*',
'type' => 'auto',
],
[
'name' => 'titles',
'type' => 'string',
'optional' => false,
'infix' => true,
'sort' => true
],
[
'name' => 'url',
'type' => 'string',
'optional' => false,
'infix' => true,
'sort' => true
],
]
];
}

public function typesenseQueryBy(): array
{
return [
Expand Down
38 changes: 29 additions & 9 deletions app/Repositories/DefaultAnimeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,39 @@ public function getItemsBySeason(
$finalFilter['$or'][] = [
// note: this expression only works with mongodb version 5.0.0 or higher
'$expr' => [
'$lte' => [
'$and' => [
[
'$dateDiff' => [
'startDate' => [
'$dateFromString' => [
'dateString' => '$aired.from'
'$lte' => [
[
'$dateDiff' => [
'startDate' => [
'$dateFromString' => [
'dateString' => '$aired.from'
]
],
'endDate' => new UTCDateTime($from),
'unit' => 'month'
]
],
'endDate' => new UTCDateTime($from),
'unit' => 'month'
]
3 // there are 3 months in a season, so anything that started in 3 months or less will be included
],
],
3 // there are 3 months in a season, so anything that started in 3 months or less will be included
[
'$gt' => [
[
'$dateDiff' => [
'startDate' => [
'$dateFromString' => [
'dateString' => '$aired.from'
]
],
'endDate' => new UTCDateTime($from),
'unit' => 'month'
]
],
0
]
]
]
],
'aired.to' => null,
Expand Down
35 changes: 35 additions & 0 deletions tests/Integration/SeasonControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,39 @@ public function testShouldNotIncludeContinuingItemsByDefault()
$this->assertIsArray($content["data"]);
$this->assertCount(2, $content["data"]);
}

public function testShouldNotIncludeNewlyStartedSeasonOfAnimeInPreviousSeasons()
{
Carbon::setTestNow(Carbon::parse("2024-10-26"));
$f = Anime::factory(1);
$startDate = "2024-10-02";
$carbonStartDate = Carbon::parse($startDate);
$state = $f->serializeStateDefinition([
"aired" => new CarbonDateRange($carbonStartDate, null)
]);
$state["aired"]["string"] = "Oct 2, 2024 to ?";
$state["airing"] = true;
$state["status"] = "Currently Airing";
$state["premiered"] = "Fall 2024";
$state["mal_id"] = 54857;
$state["title"] = "Re:Zero kara Hajimeru Isekai Seikatsu 3rd Season";
$state["episodes"] = 16;
$state["type"] = "TV";
$state["duration"] = "23 min per ep";
$state["score"] = 8.9;
$f->create($state);

$content = $this->getJsonResponse([], "/v4/seasons/now?filter=tv&continuing&page=1");
$this->seeStatusCode(200);
$this->assertCount(1, $content["data"]);

$content = $this->getJsonResponse([], "/v4/seasons/2024/summer?filter=tv&continuing&page=1");
$this->seeStatusCode(200);
$this->assertCount(0, $content["data"]);

$content = $this->getJsonResponse([], "/v4/seasons/2024/spring?filter=tv&continuing&page=1");
$this->seeStatusCode(200);
$this->assertCount(0, $content["data"]);
Carbon::setTestNow();
}
}

0 comments on commit 53508e8

Please sign in to comment.