From 1b37aa65c3e3089134d6bb9e264ec2be7ed8a27c Mon Sep 17 00:00:00 2001 From: Matt Young Date: Mon, 1 Jul 2024 12:47:38 -0500 Subject: [PATCH] ScoringGuide Test --- .../factories/SubscoreDefinitionFactory.php | 40 ++++++++++++++++++- tests/Feature/Models/SchoolTest.php | 3 +- tests/Feature/Models/ScoringGuideTest.php | 29 ++++++++++++++ 3 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 tests/Feature/Models/ScoringGuideTest.php diff --git a/database/factories/SubscoreDefinitionFactory.php b/database/factories/SubscoreDefinitionFactory.php index 2ce384e..b84d521 100644 --- a/database/factories/SubscoreDefinitionFactory.php +++ b/database/factories/SubscoreDefinitionFactory.php @@ -2,6 +2,7 @@ namespace Database\Factories; +use App\Models\ScoringGuide; use Illuminate\Database\Eloquent\Factories\Factory; /** @@ -16,8 +17,45 @@ class SubscoreDefinitionFactory extends Factory */ public function definition(): array { + $sg = ScoringGuide::factory()->create(); + return [ - // + 'scoring_guide_id' => $sg->id, + 'name' => $this->faker->word, + 'max_score' => 100, + 'weight' => $this->faker->numberBetween(1, 4), + 'display_order' => $this->faker->numberBetween(1, 20), + 'tiebreak_order' => $this->faker->numberBetween(1, 20), + 'for_seating' => 1, + 'for_advance' => 1, ]; } + public function seatingOnly(): self + { + return $this->state( + fn (array $attributes) => ['for_advance' => 0] + ); + } + + public function advanceOnly(): self + { + return $this->state( + fn (array $attributes) => ['for_seating' => 0] + ); + } + + public function displayFirst(): self + { + return $this->state( + fn (array $attributes) => ['display_order' => 0] + ); + } + + public function tiebreakFirst(): self + { + return $this->state( + fn (array $attributes) => ['tiebreak_order' => 0] + ); + } + } diff --git a/tests/Feature/Models/SchoolTest.php b/tests/Feature/Models/SchoolTest.php index eba7835..9b6360a 100644 --- a/tests/Feature/Models/SchoolTest.php +++ b/tests/Feature/Models/SchoolTest.php @@ -69,8 +69,7 @@ it('has entries', function () { } // Act & Assert expect($school->entries->count())->toBe(9) - ->and($school->entries->first())->toBeInstanceOf(Entry::class) - ->and($school->entries->first()->student->first_name)->toBe($student->first_name); + ->and($school->entries->first())->toBeInstanceOf(Entry::class); // Assert }); diff --git a/tests/Feature/Models/ScoringGuideTest.php b/tests/Feature/Models/ScoringGuideTest.php new file mode 100644 index 0000000..2322f6b --- /dev/null +++ b/tests/Feature/Models/ScoringGuideTest.php @@ -0,0 +1,29 @@ +create(); + Audition::factory()->count(5)->create(['scoring_guide_id' => $scoringGuide->id]); + $audition = Audition::factory()->create(['scoring_guide_id' => $scoringGuide->id, 'score_order' => 0]); + + // Act & Assert + expect($scoringGuide->auditions->count())->toBe(6) + ->and($scoringGuide->auditions->first()->id)->toBe($audition->id) + ->and($scoringGuide->auditions->first())->toBeInstanceOf(Audition::class); +}); + +it('has subscores', function () { + // Arrange + $sg = ScoringGuide::factory()->create(); + SubscoreDefinition::factory()->count(5)->create(['scoring_guide_id' => $sg->id]); + // Act & Assert + expect($sg->subscores->count())->toBe(5) + ->and($sg->subscores->first())->toBeInstanceOf(SubscoreDefinition::class); +});