77 lines
3.0 KiB
PHP
77 lines
3.0 KiB
PHP
<?php
|
|
|
|
use App\Models\Entry;
|
|
use App\Models\School;
|
|
use App\Models\Student;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
test('it has users that are also called directors', function () {
|
|
$school = School::factory()->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
|
|
|
|
});
|