Add doublerRequest relationship to School model
This commit is contained in:
parent
dcd1d74fdc
commit
30667a28c5
|
|
@ -28,6 +28,11 @@ class School extends Model
|
|||
return $this->hasMany(SchoolEmailDomain::class);
|
||||
}
|
||||
|
||||
public function doublerRequests()
|
||||
{
|
||||
return $this->hasManyThrough(DoublerRequest::class, Student::class);
|
||||
}
|
||||
|
||||
/** TODO: Remove this and concepts of profile picture */
|
||||
/** @codeCoverageIgnore */
|
||||
public function initialLetterImageURL($bg_color = '4f46e5', $text_color = 'fff'): string
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Audition;
|
||||
use App\Models\Doubler;
|
||||
use App\Models\DoublerRequest;
|
||||
use App\Models\Entry;
|
||||
use App\Models\NominationEnsemble;
|
||||
use App\Models\NominationEnsembleEntry;
|
||||
|
|
@ -67,3 +70,28 @@ it('returns its nominations', function () {
|
|||
expect($this->school->nominations()->count())->toEqual(3)
|
||||
->and($this->school->nominations()->first())->toBeInstanceOf(NominationEnsembleEntry::class);
|
||||
});
|
||||
|
||||
it('returns doubler requests 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);
|
||||
expect(Doubler::count())->toEqual(1);
|
||||
DoublerRequest::create([
|
||||
'event_id' => $audition->event_id,
|
||||
'student_id' => $student->id,
|
||||
'request' => 'My Request',
|
||||
]);
|
||||
$otherStudent = Student::factory()->create();
|
||||
DoublerRequest::create([
|
||||
'event_id' => $audition->event_id,
|
||||
'student_id' => $otherStudent->id,
|
||||
'request' => 'My Request',
|
||||
]);
|
||||
expect($this->school->doublerRequests()->count())->toEqual(1);
|
||||
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue