116 lines
4.4 KiB
PHP
116 lines
4.4 KiB
PHP
<?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;
|
|
use App\Models\School;
|
|
use App\Models\SchoolEmailDomain;
|
|
use App\Models\Student;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
$this->school = School::factory()->create();
|
|
});
|
|
|
|
it('returns its directors using either directors() or users()', function () {
|
|
$users = User::factory()->count(3)->create();
|
|
$users->each(function ($user) {
|
|
$user->school_id = $this->school->id;
|
|
$user->save();
|
|
});
|
|
expect($this->school->directors()->count())->toEqual(3)
|
|
->and($this->school->directors()->first())->toBeInstanceOf(User::class)
|
|
->and($this->school->users()->count())->toEqual(3)
|
|
->and($this->school->users()->first())->toBeInstanceOf(User::class);
|
|
});
|
|
|
|
it('returns its emailDomains', function () {
|
|
SchoolEmailDomain::factory()->create(['school_id' => $this->school->id]);
|
|
expect($this->school->emailDomains()->count())->toEqual(1)
|
|
->and($this->school->emailDomains()->first())->toBeInstanceOf(SchoolEmailDomain::class);
|
|
});
|
|
|
|
it('returns its students', function () {
|
|
Student::factory()->count(3)->create(['school_id' => $this->school->id]);
|
|
expect($this->school->students()->count())->toEqual(3)
|
|
->and($this->school->students()->first())->toBeInstanceOf(Student::class);
|
|
});
|
|
|
|
it('returns its entries', function () {
|
|
$students = Student::factory()->count(3)->create(['school_id' => $this->school->id]);
|
|
$students->each(function ($student) {
|
|
Entry::factory()->count(2)->create(['student_id' => $student->id]);
|
|
});
|
|
expect($this->school->entries()->count())->toEqual(6)
|
|
->and($this->school->entries()->first())->toBeInstanceOf(Entry::class);
|
|
});
|
|
|
|
it('returns its nominations', function () {
|
|
$students = Student::factory()->count(3)->create(['school_id' => $this->school->id]);
|
|
$nominationEnsemble = NominationEnsemble::create([
|
|
'name' => 'Test Ensemble',
|
|
'entry_deadline' => '2024-01-01',
|
|
'minimum_grade' => '5',
|
|
'maximum_grade' => '15',
|
|
'data' => json_encode([5, 5, 5]),
|
|
]);
|
|
$students->each(function ($student) use ($nominationEnsemble) {
|
|
NominationEnsembleEntry::create([
|
|
'student_id' => $student->id,
|
|
'nomination_ensemble_id' => $nominationEnsemble->id,
|
|
'data' => json_encode(['test' => 'test']),
|
|
]);
|
|
});
|
|
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);
|
|
|
|
});
|
|
|
|
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);
|
|
});
|