From 691d1d5f7c20306916a7671e6fa99d414214bd9d Mon Sep 17 00:00:00 2001 From: Matt Young Date: Tue, 1 Jul 2025 18:29:20 -0500 Subject: [PATCH] AddSchoolEmailDomain action and test. --- app/Actions/Schools/AddSchoolEmailDomain.php | 3 --- app/Observers/SchoolEmailDomainObserver.php | 27 +++++++++++++++++++ .../Schools/AddSchoolEmailDomainTest.php | 2 +- 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 app/Observers/SchoolEmailDomainObserver.php diff --git a/app/Actions/Schools/AddSchoolEmailDomain.php b/app/Actions/Schools/AddSchoolEmailDomain.php index 586fa7f..852d73b 100644 --- a/app/Actions/Schools/AddSchoolEmailDomain.php +++ b/app/Actions/Schools/AddSchoolEmailDomain.php @@ -31,8 +31,5 @@ class AddSchoolEmailDomain 'domain' => $domain, 'school_id' => $school->id, ]); - $message = 'Added the email domain '.$domain.' to school '.$school->name; - $affected = ['schools' => [$school->id]]; - auditionLog($message, $affected); } } diff --git a/app/Observers/SchoolEmailDomainObserver.php b/app/Observers/SchoolEmailDomainObserver.php new file mode 100644 index 0000000..0d3ba33 --- /dev/null +++ b/app/Observers/SchoolEmailDomainObserver.php @@ -0,0 +1,27 @@ +domain; + $school = School::find($schoolEmailDomain->school_id); + $message = 'Added the email domain '.$domain.' to school '.$school->name; + $affected = ['schools' => [$school->id]]; + auditionLog($message, $affected); + } + + public function deleted(SchoolEmailDomain $schoolEmailDomain): void + { + $domain = $schoolEmailDomain->domain; + $school = School::find($schoolEmailDomain->school_id); + $message = 'Added the email domain '.$domain.' to school '.$school->name; + $affected = ['schools' => [$school->id]]; + auditionLog($message, $affected); + } +} diff --git a/tests/Feature/app/Actions/Schools/AddSchoolEmailDomainTest.php b/tests/Feature/app/Actions/Schools/AddSchoolEmailDomainTest.php index 00a1b12..d129e67 100644 --- a/tests/Feature/app/Actions/Schools/AddSchoolEmailDomainTest.php +++ b/tests/Feature/app/Actions/Schools/AddSchoolEmailDomainTest.php @@ -38,5 +38,5 @@ it('silently continues if the domain is already added to the school', function ( ($this->secretary)($this->school, $this->domain); expect(SchoolEmailDomain::where('school_id', $this->school->id) ->where('domain', $this->domain)->exists())->toBeTrue() - ->and(AuditLogEntry::count())->toEqual(0); + ->and(AuditLogEntry::count())->toEqual(1); });