From 34f5dd2952cc81c2c7a01a40b6446f9022e8e41c Mon Sep 17 00:00:00 2001 From: Matt Young Date: Mon, 1 Jul 2024 12:12:52 -0500 Subject: [PATCH] Create SchoolTest.php --- tests/Feature/Models/SchoolTest.php | 76 +++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 tests/Feature/Models/SchoolTest.php diff --git a/tests/Feature/Models/SchoolTest.php b/tests/Feature/Models/SchoolTest.php new file mode 100644 index 0000000..eba7835 --- /dev/null +++ b/tests/Feature/Models/SchoolTest.php @@ -0,0 +1,76 @@ +create(); + $user = User::factory()->create(['school_id' => $school->id]); + User::factory()->count(2)->create(['school_id' => $school->id]); + User::factory()->count(2)->create(['school_id' => 103]); + + expect($school->directors->count())->toBe(3) + ->and($school->directors->first()->first_name)->toBe($user->first_name) + ->and($school->users->count())->toBe(3) + ->and($school->users->first()->first_name)->toBe($user->first_name); +}); + +test('it has email domains', function () { + $school = School::factory()->create(); + $school->emailDomains()->create(['domain' => 'example.com']); + $school->emailDomains()->create(['domain' => 'example.org']); + + expect($school->emailDomains->count())->toBe(2) + ->and($school->emailDomains->first()->domain)->toBe('example.com'); +}); + +it('can set a default image with school initial letter', function () { + // Arrange + $school = School::factory()->create(['name' => 'Example School']); + // Act & Assert + expect($school->initialLetterImageURL())->toBe('https://ui-avatars.com/api/?background=4f46e5&color=fff&name=E'); + $response = Http::get($school->initialLetterImageURL()); + expect($response->status())->toBe(200); +}); + +it('has students sorted by their name', function () { + // Arrange + $school = School::factory()->create(); + Student::factory()->create(['school_id' => $school->id, 'last_name' => 'Aaaaaa', 'first_name' => 'Zzz']); + $firstStudent = Student::factory()->create([ + 'school_id' => $school->id, 'last_name' => 'Aaaaaa', + 'first_name' => 'Aaron', + ]); + $lastStudent = Student::factory()->create(['school_id' => $school->id, 'last_name' => 'Zzzz']); + Student::factory()->count(2)->create(['school_id' => $school->id]); + + // Act & Assert + expect($school->students->count())->toBe(5) + ->and($school->students->first()->first_name)->toBe($firstStudent->first_name) + ->and($school->students->last()->first_name)->toBe($lastStudent->first_name); +}); + +it('has entries', function () { + // Arrange + $school = School::factory()->create(); + $student = Student::factory()->create(['school_id' => $school->id, 'last_name' => 'Aaaaaa']); + $entry = Entry::factory()->create(['student_id' => $student->id]); + Entry::factory()->create(['student_id' => $student->id]); + + $students = Student::factory()->count(7)->create(['school_id' => $school->id]); + foreach ($students as $student) { + Entry::factory()->create(['student_id' => $student->id]); + } + // 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); + // Assert + +});