jikan-rest/tests/Integration/ClubControllerTest.php

86 lines
2.4 KiB
PHP
Raw Normal View History

<?php /** @noinspection PhpIllegalPsrClassPathInspection */
2023-02-12 15:14:11 +00:00
namespace Tests\Integration;
use App\Club;
use App\Testing\ScoutFlush;
use App\Testing\SyntheticMongoDbTransaction;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
2019-05-13 08:52:55 +05:00
class ClubControllerTest extends TestCase
{
use SyntheticMongoDbTransaction;
use ScoutFlush;
2019-05-13 08:52:55 +05:00
public function testMain()
{
Club::factory()->createOne([
"mal_id" => 1
]);
$this->get('/v4/clubs/1')
->seeStatusCode(200)
2021-01-14 07:29:28 +05:00
->seeJsonStructure(['data'=>[
2019-05-13 08:52:55 +05:00
'mal_id',
2022-06-07 15:52:18 +02:00
'name',
2019-05-13 08:52:55 +05:00
'url',
2022-06-07 15:52:18 +02:00
'images' => [
'jpg' => [
'image_url',
],
],
'members',
2019-05-13 08:52:55 +05:00
'category',
'created',
2022-06-07 15:52:18 +02:00
'access',
2021-01-14 07:29:28 +05:00
]]);
2019-05-13 08:52:55 +05:00
}
public function testMembers()
{
$dummyUsername = $this->faker->userName();
$document = $this->dummyResultsDocument('/v4/clubs/1/members', 'clubs', [
[
"username" => $this->faker->userName(),
"url" => "https://myanimelist.net/profile/".$dummyUsername,
"images" => [
"jpg" => [
"image_url" => "http://httpbin.org/get"
],
"webp" => [
"image_url" => "http://httpbin.org/get"
]
]
]
]);
DB::table("clubs_members")->insert($document);
2022-06-07 15:52:18 +02:00
$this->get('/v4/clubs/1/members')
2019-05-13 08:52:55 +05:00
->seeStatusCode(200)
->seeJsonStructure([
2021-01-16 10:50:42 +05:00
'pagination' => [
2021-01-14 07:29:28 +05:00
'last_visible_page',
2022-06-07 15:52:18 +02:00
'has_next_page',
2021-01-14 07:29:28 +05:00
],
'data' => [
2019-05-13 08:52:55 +05:00
[
'username',
'url',
2021-01-14 07:29:28 +05:00
'images' => [
'jpg' => [
'image_url'
],
'webp' => [
'image_url'
]
],
2019-05-13 08:52:55 +05:00
]
]
]);
}
public function test404()
{
$this->mockJikanParserWith404RespondingUpstream();
2021-01-14 07:29:28 +05:00
$this->get('/v4/clubs/1000000')
2019-05-13 08:52:55 +05:00
->seeStatusCode(404);
}
}