From 4a4947f8bf47d68f84caa12110c81cd2353f2394 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Fri, 4 Jul 2025 13:17:03 -0500 Subject: [PATCH] Create test for app/Observers/SchoolEmailDomainObserver --- app/Observers/SchoolEmailDomainObserver.php | 2 +- .../SchoolEmailDomainObserverTest.php | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/Feature/app/Observers/SchoolEmailDomainObserverTest.php diff --git a/app/Observers/SchoolEmailDomainObserver.php b/app/Observers/SchoolEmailDomainObserver.php index 0d3ba33..e4b349d 100644 --- a/app/Observers/SchoolEmailDomainObserver.php +++ b/app/Observers/SchoolEmailDomainObserver.php @@ -20,7 +20,7 @@ class SchoolEmailDomainObserver { $domain = $schoolEmailDomain->domain; $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]]; auditionLog($message, $affected); } diff --git a/tests/Feature/app/Observers/SchoolEmailDomainObserverTest.php b/tests/Feature/app/Observers/SchoolEmailDomainObserverTest.php new file mode 100644 index 0000000..d4b64e0 --- /dev/null +++ b/tests/Feature/app/Observers/SchoolEmailDomainObserverTest.php @@ -0,0 +1,25 @@ +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); +});