AddSchoolEmailDomain action and test.

This commit is contained in:
Matt Young 2025-07-01 18:29:20 -05:00
parent fa3df80e3c
commit 691d1d5f7c
3 changed files with 28 additions and 4 deletions

View File

@ -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);
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace App\Observers;
use App\Models\School;
use App\Models\SchoolEmailDomain;
class SchoolEmailDomainObserver
{
public function created(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);
}
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);
}
}

View File

@ -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);
});