Skip to content

Commit

Permalink
some factory cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
notbakaneko committed Oct 24, 2023
1 parent 0f96851 commit f0848b6
Showing 1 changed file with 14 additions and 27 deletions.
41 changes: 14 additions & 27 deletions tests/Models/BeatmapsetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Jobs\Notifications\BeatmapsetDisqualify;
use App\Jobs\Notifications\BeatmapsetResetNominations;
use App\Models\Beatmap;
use App\Models\BeatmapDiscussion;
use App\Models\BeatmapMirror;
use App\Models\Beatmapset;
use App\Models\BeatmapsetNomination;
Expand All @@ -23,9 +24,6 @@

class BeatmapsetTest extends TestCase
{
private $fakeGenre;
private $fakeLanguage;

public function testLove()
{
$user = User::factory()->create();
Expand Down Expand Up @@ -161,7 +159,7 @@ public function testLimitedBNGQualifyingNominationLimitedBNGNominated()
}
public function testNominateWithDefaultMetadata()
{
$beatmapset = $this->beatmapsetFactory([
$beatmapset = $this->beatmapsetFactory()->state([
'genre_id' => Genre::UNSPECIFIED,
'language_id' => Language::UNSPECIFIED,
])->create();
Expand All @@ -177,9 +175,7 @@ public function testNominateWithDefaultMetadata()
*/
public function testRank(string $state, bool $success): void
{
$beatmapset = $this->beatmapsetFactory([
'approved' => Beatmapset::STATES[$state],
])->create();
$beatmapset = $this->beatmapsetFactory()->$state()->create();

$otherUser = User::factory()->create();

Expand All @@ -206,7 +202,9 @@ public function testRank(string $state, bool $success): void
*/
public function testRankWithOpenIssue(string $type): void
{
$beatmapset = $this->beatmapsetFactory()->qualified()->withDiscussion($type)->create();
$beatmapset = $this->beatmapsetFactory()
->qualified()
->has(BeatmapDiscussion::factory()->general()->messageType($type))->create();

$this->assertTrue($beatmapset->isQualified());
$this->assertFalse($beatmapset->rank());
Expand Down Expand Up @@ -492,33 +490,24 @@ public function rankWithOpenIssueDataProvider()
/**
* @return Factory<Beatmapset>
*/
private function beatmapsetFactory($params = []): Factory
private function beatmapsetFactory(): Factory
{
$defaultParams = [
'approved' => Beatmapset::STATES['pending'],
'download_disabled' => true,
'genre_id' => $this->fakeGenre->genre_id,
'language_id' => $this->fakeLanguage->language_id,
];

$params['user_id'] ??= User::factory();

$beatmapset = Beatmapset::factory()
->state([...$defaultParams, ...$params])
->has(Beatmap::factory()->state(fn (array $attr, Beatmapset $set) => ['user_id' => $set->user_id]));

BeatmapMirror::factory()->default()->create();

return $beatmapset;
return Beatmapset::factory()
->owner()
->pending()
->state(['download_disabled' => true])
->has(Beatmap::factory()->state(fn (array $attr, Beatmapset $set) => ['user_id' => $set->user_id]));
}

private function createHybridBeatmapset($params = [], $playmodes = ['osu', 'taiko']): Beatmapset
{
$defaultParams = [
'approved' => Beatmapset::STATES['pending'],
'download_disabled' => true,
'genre_id' => $this->fakeGenre->genre_id,
'language_id' => $this->fakeLanguage->language_id,
// 'genre_id' => $this->fakeGenre->genre_id,
// 'language_id' => $this->fakeLanguage->language_id,
];

$params['user_id'] ??= User::factory();
Expand Down Expand Up @@ -547,7 +536,5 @@ protected function setUp(): void

Genre::factory()->create(['genre_id' => Genre::UNSPECIFIED]);
Language::factory()->create(['language_id' => Language::UNSPECIFIED]);
$this->fakeGenre = Genre::factory()->create();
$this->fakeLanguage = Language::factory()->create();
}
}

0 comments on commit f0848b6

Please sign in to comment.