mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
Merge pull request #489 from jikan-me/moar-tests2
Added more tests and improved existing ones
This commit is contained in:
commit
02613f562c
@ -23,9 +23,14 @@ class AnimeFactory extends JikanMediaModelFactory
|
||||
{
|
||||
$mal_id = $this->createMalId();
|
||||
$title = $this->createTitle();
|
||||
$status = $this->faker->randomElement(["Currently Airing", "Completed", "Upcoming"]);
|
||||
$status = $this->faker->randomElement(["Currently Airing", "Finished Airing", "Not yet aired"]);
|
||||
[$aired_from, $aired_to] = $this->createActiveDateRange($status, "Currently Airing");
|
||||
|
||||
$premiered = $this->faker->randomElement(["Winter", "Spring", "Fall", "Summer"]) . " " . $this->faker->year();
|
||||
if ($status === "Not yet aired") {
|
||||
$premiered = null;
|
||||
}
|
||||
|
||||
return [
|
||||
"mal_id" => $mal_id,
|
||||
"url" => $this->createMalUrl($mal_id, "anime"),
|
||||
@ -68,7 +73,7 @@ class AnimeFactory extends JikanMediaModelFactory
|
||||
"synopsis" => "test",
|
||||
"approved" => true,
|
||||
"background" => "test",
|
||||
"premiered" => $this->faker->randomElement(["Winter", "Spring", "Fall", "Summer"]) . " " . $this->faker->year(),
|
||||
"premiered" => $premiered,
|
||||
"broadcast" => [
|
||||
"day" => "",
|
||||
"time" => "",
|
||||
|
@ -120,24 +120,24 @@ class AnimeSearchEndpointTest extends TestCase
|
||||
public function commonParameterProvider(): array
|
||||
{
|
||||
return [
|
||||
[["status" => "airing"]],
|
||||
[["status" => "complete"]],
|
||||
[["status" => "upcoming"]],
|
||||
[["status" => "Airing"]],
|
||||
[["status" => "Complete"]],
|
||||
[["status" => "Upcoming"]],
|
||||
[["max_score" => "8"]],
|
||||
[["min_score" => "6"]],
|
||||
[["max_score" => "7", "min_score" => "3"]],
|
||||
[["rating" => "pg"]],
|
||||
[["rating" => "rx"]],
|
||||
[["rating" => "r"]],
|
||||
[["rating" => "pg13"]],
|
||||
[["rating" => "g"]],
|
||||
[["rating" => "r17"]],
|
||||
[["type" => "movie"]],
|
||||
[["type" => "ova"]],
|
||||
[["type" => "special"]],
|
||||
"status = airing" => [["status" => "airing"]],
|
||||
"status = complete" => [["status" => "complete"]],
|
||||
"status = upcoming" => [["status" => "upcoming"]],
|
||||
"status = Airing" => [["status" => "Airing"]],
|
||||
"status = Complete" => [["status" => "Complete"]],
|
||||
"status = Upcoming" => [["status" => "Upcoming"]],
|
||||
"max_score = 8" => [["max_score" => "8"]],
|
||||
"min_score = 6" => [["min_score" => "6"]],
|
||||
"max_score = 7, min_score = 3" => [["max_score" => "7", "min_score" => "3"]],
|
||||
"rating = pg" => [["rating" => "pg"]],
|
||||
"rating = rx" => [["rating" => "rx"]],
|
||||
"rating = r" => [["rating" => "r"]],
|
||||
"rating = pg13" => [["rating" => "pg13"]],
|
||||
"rating = g" => [["rating" => "g"]],
|
||||
"rating = r17" => [["rating" => "r17"]],
|
||||
"type = movie" => [["type" => "movie"]],
|
||||
"type = ova" => [["type" => "ova"]],
|
||||
"type = special" => [["type" => "special"]],
|
||||
];
|
||||
}
|
||||
|
||||
|
52
tests/Integration/SeasonControllerTest.php
Normal file
52
tests/Integration/SeasonControllerTest.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/** @noinspection PhpIllegalPsrClassPathInspection */
|
||||
namespace Tests\Integration;
|
||||
|
||||
use App\Anime;
|
||||
use App\CarbonDateRange;
|
||||
use App\Testing\ScoutFlush;
|
||||
use App\Testing\SyntheticMongoDbTransaction;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Tests\TestCase;
|
||||
|
||||
|
||||
class SeasonControllerTest extends TestCase
|
||||
{
|
||||
use SyntheticMongoDbTransaction;
|
||||
use ScoutFlush;
|
||||
|
||||
public function testShouldFilterOutAnimeWithGarbledAiredString()
|
||||
{
|
||||
Carbon::setTestNow(Carbon::parse("2024-01-11"));
|
||||
// the wrong item
|
||||
$f = Anime::factory(1);
|
||||
$startDate = "2024-01-01";
|
||||
$carbonStartDate = Carbon::parse($startDate);
|
||||
$state = $f->serializeStateDefinition([
|
||||
"aired" => new CarbonDateRange($carbonStartDate, null)
|
||||
]);
|
||||
$state["aired"]["string"] = "Jan 1, 2024 to ?";
|
||||
$state["premiered"] = null;
|
||||
$state["status"] = "Not yet aired";
|
||||
$state["airing"] = false;
|
||||
$f->create($state);
|
||||
|
||||
// the correct item
|
||||
$f = Anime::factory(1);
|
||||
$state = $f->serializeStateDefinition([
|
||||
"aired" => new CarbonDateRange(Carbon::parse("2024-01-10"), Carbon::parse("2024-02-15"))
|
||||
]);
|
||||
$state["premiered"] = "Winter 2024";
|
||||
$state["status"] = "Currently Airing";
|
||||
$state["airing"] = true;
|
||||
$f->create($state);
|
||||
|
||||
$content = $this->getJsonResponse([], "/v4/seasons/2024/winter");
|
||||
|
||||
Carbon::setTestNow();
|
||||
|
||||
$this->seeStatusCode(200);
|
||||
$this->assertIsArray($content["data"]);
|
||||
$this->assertCount(1, $content["data"]);
|
||||
}
|
||||
}
|
45
tests/Unit/PreparesDataTraitTest.php
Normal file
45
tests/Unit/PreparesDataTraitTest.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/** @noinspection PhpIllegalPsrClassPathInspection */
|
||||
namespace Tests\Unit;
|
||||
use App\Dto\Concerns\HasLimitParameter;
|
||||
use App\Dto\Concerns\HasPageParameter;
|
||||
use App\Dto\Concerns\PreparesData;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\Optional;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class PreparesDataFixture extends Data
|
||||
{
|
||||
use PreparesData, HasLimitParameter, HasPageParameter;
|
||||
|
||||
public string|Optional $filter;
|
||||
}
|
||||
|
||||
final class PreparesDataTraitTest extends TestCase
|
||||
{
|
||||
public function paramsDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'limit = empty, page = empty, filter = empty' => [['limit' => '', 'page' => '', 'filter' => ''], []],
|
||||
'limit = 1, page = empty, filter = empty' => [['limit' => '1', 'page' => '', 'filter' => ''], ['limit' => 1]],
|
||||
'limit = 1, page = 2, filter = empty' => [
|
||||
['limit' => '1', 'page' => '2', 'filter' => ''],
|
||||
['limit' => 1, 'page' => 2]
|
||||
],
|
||||
'limit = 1, page = 2, filter = somefilter' => [
|
||||
['limit' => '1', 'page' => '2', 'filter' => 'somefilter'],
|
||||
['limit' => 1, 'page' => 2, 'filter' => 'somefilter']
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider paramsDataProvider
|
||||
*/
|
||||
public function testShouldIgnoreEmptyParams($actual, $expected)
|
||||
{
|
||||
$sut = PreparesDataFixture::prepareForPipeline(collect($actual));
|
||||
|
||||
$this->assertCollectionsStrictlyEqual(collect($expected), $sut);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user