-
-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #489 from jikan-me/moar-tests2
Added more tests and improved existing ones
- Loading branch information
Showing
4 changed files
with
122 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |