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,8 +385,24 @@ class CheckoutableListener
|
||||||
|
|
||||||
private function shouldNotSendAnyNotifications($checkoutable): bool
|
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
|
private function shouldSendWebhookNotification(): bool
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
namespace Tests\Feature\Notifications\Email;
|
namespace Tests\Feature\Notifications\Email;
|
||||||
|
|
||||||
use App\Mail\CheckinAssetMail;
|
use App\Mail\CheckinAssetMail;
|
||||||
|
use App\Models\Accessory;
|
||||||
|
use App\Models\Consumable;
|
||||||
|
use App\Models\LicenseSeat;
|
||||||
use Illuminate\Support\Facades\Mail;
|
use Illuminate\Support\Facades\Mail;
|
||||||
use PHPUnit\Framework\Attributes\Group;
|
use PHPUnit\Framework\Attributes\Group;
|
||||||
use App\Events\CheckoutableCheckedIn;
|
use App\Events\CheckoutableCheckedIn;
|
||||||
|
@ -45,20 +48,49 @@ class EmailNotificationsUponCheckinTest extends TestCase
|
||||||
Mail::fake();
|
Mail::fake();
|
||||||
|
|
||||||
$user = User::factory()->create();
|
$user = User::factory()->create();
|
||||||
$asset = Asset::factory()->assignedToUser($user)->create();
|
$checkoutables = collect([
|
||||||
|
Asset::factory()->assignedToUser($user)->create(),
|
||||||
|
LicenseSeat::factory()->assignedToUser($user)->create(),
|
||||||
|
Accessory::factory()->checkedOutToUser($user)->create(),
|
||||||
|
Consumable::factory()->checkedOutToUser($user)->create(),
|
||||||
|
]);
|
||||||
|
|
||||||
$asset->model->category->update([
|
foreach ($checkoutables as $checkoutable) {
|
||||||
|
|
||||||
|
if ($checkoutable instanceof Asset) {
|
||||||
|
$checkoutable->model->category->update([
|
||||||
'checkin_email' => false,
|
'checkin_email' => false,
|
||||||
'eula_text' => null,
|
'eula_text' => null,
|
||||||
'require_acceptance' => false,
|
'require_acceptance' => false,
|
||||||
]);
|
]);
|
||||||
|
$checkoutable = $checkoutable->fresh(['model.category']);
|
||||||
|
}
|
||||||
|
|
||||||
$this->fireCheckInEvent($asset, $user);
|
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) {
|
Mail::assertNotSent(CheckinAssetMail::class, function ($mail) use ($user) {
|
||||||
return $mail->hasTo($user->email);
|
return $mail->hasTo($user->email);
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function fireCheckInEvent($asset, $user): void
|
private function fireCheckInEvent($asset, $user): void
|
||||||
|
|
Loading…
Add table
Reference in a new issue