Create test for app/Observers/SchoolEmailDomainObserver

This commit is contained in:
Matt Young 2025-07-04 13:17:03 -05:00
parent 429b26b3f7
commit 4a4947f8bf
2 changed files with 26 additions and 1 deletions

View File

@ -20,7 +20,7 @@ class SchoolEmailDomainObserver
{ {
$domain = $schoolEmailDomain->domain; $domain = $schoolEmailDomain->domain;
$school = School::find($schoolEmailDomain->school_id); $school = School::find($schoolEmailDomain->school_id);
$message = 'Added the email domain '.$domain.' to school '.$school->name; $message = 'Removed the email domain '.$domain.' from school '.$school->name;
$affected = ['schools' => [$school->id]]; $affected = ['schools' => [$school->id]];
auditionLog($message, $affected); auditionLog($message, $affected);
} }

View File

@ -0,0 +1,25 @@
<?php
use App\Models\AuditLogEntry;
use App\Models\School;
use App\Models\SchoolEmailDomain;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
it('logs when a school email domain is created', function () {
$school = School::factory()->create();
SchoolEmailDomain::create([
'domain' => 'test.com',
'school_id' => $school->id,
]);
$lastLog = AuditLogEntry::latest()->first();
expect($lastLog->message)->toEqual('Added the email domain test.com to school '.$school->name);
});
it('logs when a school email domain is deleted', function () {
$domain = SchoolEmailDomain::factory()->create();
$domain->delete();
$lastLog = AuditLogEntry::orderBy('id', 'desc')->first();
expect($lastLog->message)->toEqual('Removed the email domain '.$domain->domain.' from school '.$domain->school->name);
});