Create tests for app/Models/School
This commit is contained in:
parent
f831ad6cbd
commit
08fd7a215a
|
|
@ -28,6 +28,8 @@ class School extends Model
|
||||||
return $this->hasMany(SchoolEmailDomain::class);
|
return $this->hasMany(SchoolEmailDomain::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** TODO: Remove this and concepts of profile picture */
|
||||||
|
/** @codeCoverageIgnore */
|
||||||
public function initialLetterImageURL($bg_color = '4f46e5', $text_color = 'fff'): string
|
public function initialLetterImageURL($bg_color = '4f46e5', $text_color = 'fff'): string
|
||||||
{
|
{
|
||||||
$img = "https://ui-avatars.com/api/?background=$bg_color&color=$text_color&name=";
|
$img = "https://ui-avatars.com/api/?background=$bg_color&color=$text_color&name=";
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,69 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue