mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
fixed season endpoint's continuing flag #555
This commit is contained in:
parent
744bd69aea
commit
705e0fbf36
@ -167,19 +167,39 @@ final class DefaultAnimeRepository extends DatabaseRepository implements AnimeRe
|
|||||||
$finalFilter['$or'][] = [
|
$finalFilter['$or'][] = [
|
||||||
// note: this expression only works with mongodb version 5.0.0 or higher
|
// note: this expression only works with mongodb version 5.0.0 or higher
|
||||||
'$expr' => [
|
'$expr' => [
|
||||||
'$lte' => [
|
'$and' => [
|
||||||
[
|
[
|
||||||
'$dateDiff' => [
|
'$lte' => [
|
||||||
'startDate' => [
|
[
|
||||||
'$dateFromString' => [
|
'$dateDiff' => [
|
||||||
'dateString' => '$aired.from'
|
'startDate' => [
|
||||||
|
'$dateFromString' => [
|
||||||
|
'dateString' => '$aired.from'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'endDate' => new UTCDateTime($from),
|
||||||
|
'unit' => 'month'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'endDate' => new UTCDateTime($from),
|
3 // there are 3 months in a season, so anything that started in 3 months or less will be included
|
||||||
'unit' => 'month'
|
],
|
||||||
]
|
|
||||||
],
|
],
|
||||||
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,
|
'aired.to' => null,
|
||||||
|
@ -190,4 +190,39 @@ class SeasonControllerTest extends TestCase
|
|||||||
$this->assertIsArray($content["data"]);
|
$this->assertIsArray($content["data"]);
|
||||||
$this->assertCount(2, $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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user