adds a check for category checkin/out emails, also updates our test
This commit is contained in:
parent
ce94470a10
commit
c8b5b3f176
2 changed files with 59 additions and 11 deletions
|
@ -385,9 +385,25 @@ class CheckoutableListener
|
|||
|
||||
private function shouldNotSendAnyNotifications($checkoutable): bool
|
||||
{
|
||||
return in_array(get_class($checkoutable), $this->skipNotificationsFor);
|
||||
if(in_array(get_class($checkoutable), $this->skipNotificationsFor)) {
|
||||
return true;
|
||||
}
|
||||
//runs a check if the category wants to send checkin/checkout emails to users
|
||||
$category = match (true) {
|
||||
$checkoutable instanceof Asset => $checkoutable->model->category,
|
||||
$checkoutable instanceof Accessory,
|
||||
$checkoutable instanceof Consumable => $checkoutable->category,
|
||||
$checkoutable instanceof LicenseSeat => $checkoutable->license->category,
|
||||
default => null,
|
||||
};
|
||||
|
||||
if (!$category->checkin_email) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private function shouldSendWebhookNotification(): bool
|
||||
{
|
||||
return Setting::getSettings() && Setting::getSettings()->webhook_endpoint;
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
namespace Tests\Feature\Notifications\Email;
|
||||
|
||||
use App\Mail\CheckinAssetMail;
|
||||
use App\Models\Accessory;
|
||||
use App\Models\Consumable;
|
||||
use App\Models\LicenseSeat;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
use App\Events\CheckoutableCheckedIn;
|
||||
|
@ -45,20 +48,49 @@ class EmailNotificationsUponCheckinTest extends TestCase
|
|||
Mail::fake();
|
||||
|
||||
$user = User::factory()->create();
|
||||
$asset = Asset::factory()->assignedToUser($user)->create();
|
||||
|
||||
$asset->model->category->update([
|
||||
'checkin_email' => false,
|
||||
'eula_text' => null,
|
||||
'require_acceptance' => false,
|
||||
$checkoutables = collect([
|
||||
Asset::factory()->assignedToUser($user)->create(),
|
||||
LicenseSeat::factory()->assignedToUser($user)->create(),
|
||||
Accessory::factory()->checkedOutToUser($user)->create(),
|
||||
Consumable::factory()->checkedOutToUser($user)->create(),
|
||||
]);
|
||||
|
||||
$this->fireCheckInEvent($asset, $user);
|
||||
foreach ($checkoutables as $checkoutable) {
|
||||
|
||||
Mail::assertNotSent(CheckinAssetMail::class, function($mail) use ($user) {
|
||||
return $mail->hasTo($user->email);
|
||||
if ($checkoutable instanceof Asset) {
|
||||
$checkoutable->model->category->update([
|
||||
'checkin_email' => false,
|
||||
'eula_text' => null,
|
||||
'require_acceptance' => false,
|
||||
]);
|
||||
$checkoutable = $checkoutable->fresh(['model.category']);
|
||||
}
|
||||
);
|
||||
|
||||
if ($checkoutable instanceof Accessory || $checkoutable instanceof \App\Models\Consumable) {
|
||||
$checkoutable->category->update([
|
||||
'checkin_email' => false,
|
||||
'eula_text' => null,
|
||||
'require_acceptance' => false,
|
||||
]);
|
||||
$checkoutable = $checkoutable->fresh(['category']);
|
||||
}
|
||||
|
||||
if ($checkoutable instanceof LicenseSeat) {
|
||||
$checkoutable->license->category->update([
|
||||
'checkin_email' => false,
|
||||
'eula_text' => null,
|
||||
'require_acceptance' => false,
|
||||
]);
|
||||
$checkoutable = $checkoutable->fresh(['license.category']);
|
||||
}
|
||||
|
||||
// Fire event manually
|
||||
$this->fireCheckInEvent($checkoutable, $user);
|
||||
}
|
||||
|
||||
Mail::assertNotSent(CheckinAssetMail::class, function ($mail) use ($user) {
|
||||
return $mail->hasTo($user->email);
|
||||
});
|
||||
}
|
||||
|
||||
private function fireCheckInEvent($asset, $user): void
|
||||
|
|
Loading…
Add table
Reference in a new issue