diff --git a/app/Models/School.php b/app/Models/School.php index 2511a0e..9fa6f7d 100644 --- a/app/Models/School.php +++ b/app/Models/School.php @@ -33,6 +33,11 @@ class School extends Model return $this->hasManyThrough(DoublerRequest::class, Student::class); } + public function doublers() + { + return $this->hasManyThrough(Doubler::class, Student::class); + } + /** TODO: Remove this and concepts of profile picture */ /** @codeCoverageIgnore */ public function initialLetterImageURL($bg_color = '4f46e5', $text_color = 'fff'): string diff --git a/tests/Feature/app/Models/SchoolTest.php b/tests/Feature/app/Models/SchoolTest.php index de59341..a496148 100644 --- a/tests/Feature/app/Models/SchoolTest.php +++ b/tests/Feature/app/Models/SchoolTest.php @@ -95,3 +95,21 @@ it('returns doubler requests for its students', function () { expect($this->school->doublerRequests()->count())->toEqual(1); }); + +it('returns doublers for its students', function () { + $student = Student::factory()->forSchool($this->school)->create(['grade' => 8]); + $audition = Audition::factory()->create(['minimum_grade' => 8, 'maximum_grade' => 8]); + $audition2 = Audition::factory()->forEvent($audition->event)->create([ + 'minimum_grade' => 8, 'maximum_grade' => 8, + ]); + $entryCreator = app(\App\Actions\Entries\CreateEntry::class); + $entryCreator($student, $audition); + $entryCreator($student, $audition2); + + $otherStudent = Student::factory()->create(['grade' => 8]); + $entryCreator($otherStudent, $audition); + $entryCreator($otherStudent, $audition2); + expect(Doubler::count())->toEqual(2); + + expect($this->school->doublers()->count())->toEqual(1); +});