mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
add Anime tests
This commit is contained in:
parent
d9b51f66ce
commit
977786f3e3
@ -81,9 +81,13 @@ class GithubReport
|
|||||||
$report->requestMethod = $request->getMethod();
|
$report->requestMethod = $request->getMethod();
|
||||||
$report->jikanVersion = Versions::getVersion('jikan-me/jikan');
|
$report->jikanVersion = Versions::getVersion('jikan-me/jikan');
|
||||||
$report->redisRunning = trim(app('redis')->ping()) === 'PONG' ? "Connected" : "Disconnected";
|
$report->redisRunning = trim(app('redis')->ping()) === 'PONG' ? "Connected" : "Disconnected";
|
||||||
$report->instanceType = $_SERVER['SERVER_NAME'] === 'api.jikan.moe' ? 'OFFICIAL' : 'HOSTED';
|
|
||||||
$report->phpVersion = PHP_VERSION;
|
$report->phpVersion = PHP_VERSION;
|
||||||
|
|
||||||
|
$report->instanceType = 'UNKNOWN';
|
||||||
|
if (env('APP_ENV') !== 'testing') {
|
||||||
|
$report->instanceType = $_SERVER['SERVER_NAME'] === 'api.jikan.moe' ? 'OFFICIAL' : 'HOSTED';
|
||||||
|
}
|
||||||
|
|
||||||
return $report;
|
return $report;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,12 +16,10 @@
|
|||||||
|
|
||||||
namespace App\Http\Middleware;
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
use App\Http\Controllers\V3\ScheduleController;
|
|
||||||
use App\Http\HttpHelper;
|
use App\Http\HttpHelper;
|
||||||
use App\Jobs\UpdateCacheJob;
|
use App\Jobs\UpdateCacheJob;
|
||||||
use Closure;
|
use Closure;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use phpDocumentor\Reflection\Types\Self_;
|
|
||||||
|
|
||||||
class JikanResponseHandler
|
class JikanResponseHandler
|
||||||
{
|
{
|
||||||
|
@ -13,8 +13,8 @@ try {
|
|||||||
/*
|
/*
|
||||||
Defines
|
Defines
|
||||||
*/
|
*/
|
||||||
define('BLACKLIST_PATH', __DIR__.'/../storage/app/blacklist.json');
|
defined('BLACKLIST_PATH') or define('BLACKLIST_PATH', __DIR__.'/../storage/app/blacklist.json');
|
||||||
define('JIKAN_PARSER_VERSION', Versions::getVersion('jikan-me/jikan'));
|
defined('JIKAN_PARSER_VERSION') or define('JIKAN_PARSER_VERSION', Versions::getVersion('jikan-me/jikan'));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
</filter>
|
</filter>
|
||||||
<php>
|
<php>
|
||||||
<env name="APP_ENV" value="testing"/>
|
<env name="APP_ENV" value="testing"/>
|
||||||
<env name="CACHE_DRIVER" value="array"/>
|
<env name="CACHE_DRIVER" value="redis"/>
|
||||||
<env name="QUEUE_DRIVER" value="sync"/>
|
<env name="QUEUE_DRIVER" value="redis"/>
|
||||||
</php>
|
</php>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use Laravel\Lumen\Testing\DatabaseMigrations;
|
|
||||||
use Laravel\Lumen\Testing\DatabaseTransactions;
|
|
||||||
|
|
||||||
class ExampleTest extends TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* A basic test example.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testExample()
|
|
||||||
{
|
|
||||||
$this->get('/');
|
|
||||||
|
|
||||||
$this->assertEquals(
|
|
||||||
$this->app->version(),
|
|
||||||
$this->response->getContent()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
364
tests/Http/Controllers/AnimeControllerTest.php
Normal file
364
tests/Http/Controllers/AnimeControllerTest.php
Normal file
@ -0,0 +1,364 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class AnimeControllerTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testMain()
|
||||||
|
{
|
||||||
|
$this->get('/v3/anime/1')
|
||||||
|
->seeStatusCode(200)
|
||||||
|
->seeJsonStructure([
|
||||||
|
'mal_id',
|
||||||
|
'url',
|
||||||
|
'image_url',
|
||||||
|
'trailer_url',
|
||||||
|
'title',
|
||||||
|
'title_english',
|
||||||
|
'title_japanese',
|
||||||
|
'title_synonyms',
|
||||||
|
'type',
|
||||||
|
'source',
|
||||||
|
'episodes',
|
||||||
|
'status',
|
||||||
|
'airing',
|
||||||
|
'aired' => [
|
||||||
|
'from',
|
||||||
|
'to',
|
||||||
|
'prop' => [
|
||||||
|
'from' => [
|
||||||
|
'day',
|
||||||
|
'month',
|
||||||
|
'year'
|
||||||
|
],
|
||||||
|
'to' => [
|
||||||
|
'day',
|
||||||
|
'month',
|
||||||
|
'year'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'string'
|
||||||
|
],
|
||||||
|
'duration',
|
||||||
|
'rating',
|
||||||
|
'score',
|
||||||
|
'scored_by',
|
||||||
|
'rank',
|
||||||
|
'popularity',
|
||||||
|
'members',
|
||||||
|
'favorites',
|
||||||
|
'synopsis',
|
||||||
|
'background',
|
||||||
|
'premiered',
|
||||||
|
'broadcast',
|
||||||
|
'related' => [
|
||||||
|
'Adaptation' => [
|
||||||
|
[
|
||||||
|
'mal_id',
|
||||||
|
'type',
|
||||||
|
'name',
|
||||||
|
'url'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'Side story' => [
|
||||||
|
[
|
||||||
|
'mal_id',
|
||||||
|
'type',
|
||||||
|
'name',
|
||||||
|
'url'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
// ...
|
||||||
|
],
|
||||||
|
'producers' => [
|
||||||
|
[
|
||||||
|
'mal_id',
|
||||||
|
'type',
|
||||||
|
'name',
|
||||||
|
'url'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'licensors' => [
|
||||||
|
[
|
||||||
|
'mal_id',
|
||||||
|
'type',
|
||||||
|
'name',
|
||||||
|
'url'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'studios' => [
|
||||||
|
[
|
||||||
|
'mal_id',
|
||||||
|
'type',
|
||||||
|
'name',
|
||||||
|
'url'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'genres' => [
|
||||||
|
[
|
||||||
|
'mal_id',
|
||||||
|
'type',
|
||||||
|
'name',
|
||||||
|
'url'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'opening_themes',
|
||||||
|
'ending_themes'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCharactersStaff()
|
||||||
|
{
|
||||||
|
$this->get('/v3/anime/1/characters_staff')
|
||||||
|
->seeStatusCode(200)
|
||||||
|
->seeJsonStructure([
|
||||||
|
'characters' => [
|
||||||
|
[
|
||||||
|
'mal_id',
|
||||||
|
'url',
|
||||||
|
'image_url',
|
||||||
|
'name',
|
||||||
|
'voice_actors' => [
|
||||||
|
[
|
||||||
|
'mal_id',
|
||||||
|
'name',
|
||||||
|
'image_url',
|
||||||
|
'language'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'staff' => [
|
||||||
|
[
|
||||||
|
'mal_id',
|
||||||
|
'url',
|
||||||
|
'name',
|
||||||
|
'image_url',
|
||||||
|
'positions'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEpisodes()
|
||||||
|
{
|
||||||
|
$this->get('/v3/anime/1/episodes')
|
||||||
|
->seeStatusCode(200)
|
||||||
|
->seeJsonStructure([
|
||||||
|
'episodes_last_page',
|
||||||
|
'episodes' => [
|
||||||
|
[
|
||||||
|
'episode_id',
|
||||||
|
'title',
|
||||||
|
'title_japanese',
|
||||||
|
'title_romanji',
|
||||||
|
'aired',
|
||||||
|
'filler',
|
||||||
|
'recap',
|
||||||
|
'video_url',
|
||||||
|
'forum_url'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->get('/v3/anime/1/episodes/2')
|
||||||
|
->seeStatusCode(200)
|
||||||
|
->seeJson([
|
||||||
|
'episodes' => []
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNews()
|
||||||
|
{
|
||||||
|
$this->get('/v3/anime/1/news')
|
||||||
|
->seeStatusCode(200)
|
||||||
|
->seeJsonStructure([
|
||||||
|
'articles' => [
|
||||||
|
[
|
||||||
|
'url',
|
||||||
|
'title',
|
||||||
|
'date',
|
||||||
|
'author_name',
|
||||||
|
'author_url',
|
||||||
|
'forum_url',
|
||||||
|
'image_url',
|
||||||
|
'comments',
|
||||||
|
'intro'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPictures()
|
||||||
|
{
|
||||||
|
$this->get('/v3/anime/1/pictures')
|
||||||
|
->seeStatusCode(200)
|
||||||
|
->seeJsonStructure([
|
||||||
|
'pictures' => [
|
||||||
|
[
|
||||||
|
'large',
|
||||||
|
'small',
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testVideos()
|
||||||
|
{
|
||||||
|
$this->get('/v3/anime/1/videos')
|
||||||
|
->seeStatusCode(200)
|
||||||
|
->seeJsonStructure([
|
||||||
|
'promo' => [
|
||||||
|
[
|
||||||
|
'title',
|
||||||
|
'image_url',
|
||||||
|
'video_url',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'episodes' => [
|
||||||
|
[
|
||||||
|
'title',
|
||||||
|
'episode',
|
||||||
|
'url',
|
||||||
|
'image_url',
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testStats()
|
||||||
|
{
|
||||||
|
$this->get('/v3/anime/1/stats')
|
||||||
|
->seeStatusCode(200)
|
||||||
|
->seeJsonStructure([
|
||||||
|
'watching',
|
||||||
|
'completed',
|
||||||
|
'on_hold',
|
||||||
|
'dropped',
|
||||||
|
'plan_to_watch',
|
||||||
|
'total',
|
||||||
|
'scores' => [
|
||||||
|
1 => [
|
||||||
|
'votes',
|
||||||
|
'percentage'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testForum()
|
||||||
|
{
|
||||||
|
$this->get('/v3/anime/1/forum')
|
||||||
|
->seeStatusCode(200)
|
||||||
|
->seeJsonStructure([
|
||||||
|
'topics' => [
|
||||||
|
[
|
||||||
|
'topic_id',
|
||||||
|
'url',
|
||||||
|
'title',
|
||||||
|
'date_posted',
|
||||||
|
'author_name',
|
||||||
|
'author_url',
|
||||||
|
'replies',
|
||||||
|
'last_post' => [
|
||||||
|
'url',
|
||||||
|
'author_name',
|
||||||
|
'author_url',
|
||||||
|
'date_posted'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMoreInfo()
|
||||||
|
{
|
||||||
|
$this->get('/v3/anime/1/moreinfo')
|
||||||
|
->seeStatusCode(200)
|
||||||
|
->seeJsonStructure([
|
||||||
|
'moreinfo'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testReviews()
|
||||||
|
{
|
||||||
|
$this->get('/v3/anime/1/reviews')
|
||||||
|
->seeStatusCode(200)
|
||||||
|
->seeJsonStructure([
|
||||||
|
'reviews' => [
|
||||||
|
[
|
||||||
|
'mal_id',
|
||||||
|
'url',
|
||||||
|
'helpful_count',
|
||||||
|
'date',
|
||||||
|
'reviewer' => [
|
||||||
|
'url',
|
||||||
|
'image_url',
|
||||||
|
'username',
|
||||||
|
'episodes_seen',
|
||||||
|
'scores' => [
|
||||||
|
'overall',
|
||||||
|
'story',
|
||||||
|
'animation',
|
||||||
|
'sound',
|
||||||
|
'character',
|
||||||
|
'enjoyment'
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'content'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->get('/v3/anime/1/reviews/100')
|
||||||
|
->seeStatusCode(200)
|
||||||
|
->seeJsonStructure([
|
||||||
|
'reviews' => []
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRecommendations()
|
||||||
|
{
|
||||||
|
$this->get('/v3/anime/1/recommendations')
|
||||||
|
->seeStatusCode(200)
|
||||||
|
->seeJsonStructure([
|
||||||
|
'recommendations' => [
|
||||||
|
[
|
||||||
|
'mal_id',
|
||||||
|
'url',
|
||||||
|
'image_url',
|
||||||
|
'recommendation_url',
|
||||||
|
'title',
|
||||||
|
'recommendation_count'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUserUpdates()
|
||||||
|
{
|
||||||
|
$this->get('/v3/anime/1/userupdates')
|
||||||
|
->seeStatusCode(200)
|
||||||
|
->seeJsonStructure([
|
||||||
|
'users' => [
|
||||||
|
[
|
||||||
|
'username',
|
||||||
|
'url',
|
||||||
|
'image_url',
|
||||||
|
'score',
|
||||||
|
'status',
|
||||||
|
'episodes_seen',
|
||||||
|
'episodes_total',
|
||||||
|
'date'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->get('/v3/anime/1/userupdates/1000')
|
||||||
|
->seeStatusCode(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test404()
|
||||||
|
{
|
||||||
|
$this->get('/v3/anime/2')
|
||||||
|
->seeStatusCode(404);
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,7 @@ abstract class TestCase extends Laravel\Lumen\Testing\TestCase
|
|||||||
*
|
*
|
||||||
* @return \Laravel\Lumen\Application
|
* @return \Laravel\Lumen\Application
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function createApplication()
|
public function createApplication()
|
||||||
{
|
{
|
||||||
return require __DIR__.'/../bootstrap/app.php';
|
return require __DIR__.'/../bootstrap/app.php';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user