Skip to content

A free open source IT asset/license management system

messing with the tests

Godfrey M1e31592c553e
diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php
index ff76ae020e..9c8abbcee8 100644
--- a/app/Listeners/CheckoutableListener.php
+++ b/app/Listeners/CheckoutableListener.php
@@ -59,16 +59,15 @@ class CheckoutableListener
$mailable->locale($event->checkedOutTo->locale);
}
- /**
- * Send an email if any of the following conditions are met:
- * 1. The asset requires acceptance
- * 2. The item has a EULA
- * 3. The item should send an email at check-in/check-out
- */
- if ($notifiable instanceof User && $notifiable->email != '') {
- if ($event->checkoutable->requireAcceptance() || $event->checkoutable->getEula() ||
- (method_exists($event->checkoutable, 'checkin_email') && $event->checkoutable->checkin_email())) {
-
+ /**
+ * Send an email if any of the following conditions are met:
+ * 1. The asset requires acceptance
+ * 2. The item has a EULA
+ * 3. The item should send an email at check-in/check-out
+ */
+ if ($notifiable instanceof User && $notifiable->email != '') {
+ if ($event->checkoutable->requireAcceptance() || $event->checkoutable->getEula() ||
+ (method_exists($event->checkoutable, 'checkin_email') && $event->checkoutable->checkin_email())) {
Mail::to($notifiable)->send($mailable);
Log::info('Sending email, Locale: ' . ($event->checkedOutTo->locale ?? 'default'));
}
@@ -115,14 +114,25 @@ class CheckoutableListener
$notifiable = $event->checkedInBy;
$mailable = $this->getCheckinMailType($event);
-
// Send email notifications
try {
if (!$event->checkedOutTo->locale){
$mailable->locale($event->checkedOutTo->locale);
}
- Mail::to($notifiable)->send($mailable);
- \Log::info('Sending email, Locale: ' .$event->checkedOutTo->locale);
+ /**
+ * Send an email if any of the following conditions are met:
+ * 1. The asset requires acceptance
+ * 2. The item has a EULA
+ * 3. The item should send an email at check-in/check-out
+ */
+
+ if ($notifiable instanceof User && $notifiable->email != '') {
+ if ($event->checkoutable->requireAcceptance() || $event->checkoutable->getEula() ||
+ (method_exists($event->checkoutable, 'checkin_email') && $event->checkoutable->checkin_email())) {
+ Mail::to($notifiable)->send($mailable);
+ Log::info('Sending email, Locale: ' . $event->checkedOutTo->locale);
+ }
+ }
// Send Webhook notification
if ($this->shouldSendWebhookNotification()) {
Notification::route(Setting::getSettings()->webhook_selected, Setting::getSettings()->webhook_endpoint)
diff --git a/tests/Feature/Checkins/Ui/AccessoryCheckinTest.php b/tests/Feature/Checkins/Ui/AccessoryCheckinTest.php
index 419bead5a0..b5fe540ae5 100644
--- a/tests/Feature/Checkins/Ui/AccessoryCheckinTest.php
+++ b/tests/Feature/Checkins/Ui/AccessoryCheckinTest.php
@@ -3,7 +3,7 @@
namespace Tests\Feature\Checkins\Ui;
use App\Events\CheckoutableCheckedIn;
-use App\Mail\CheckoutAccessoryMail;
+use App\Mail\CheckinAccessoryMail;
use App\Models\Accessory;
use App\Models\User;
use App\Notifications\CheckinAccessoryNotification;
@@ -56,8 +56,8 @@ class AccessoryCheckinTest extends TestCase
'',
));
- Mail::assertSent(CheckoutAccessoryMail::class, function ($mail) use ($accessory, $user) {
- return $mail->hasTo($user) && $mail->contains($accessory);
+ Mail::assertSent(CheckinAccessoryMail::class, function ($mail) use ( $user) {
+ return $mail->hasTo($user->email);
});
}
@@ -77,7 +77,7 @@ class AccessoryCheckinTest extends TestCase
'',
));
- Mail::assertNotSent(CheckoutAccessoryMail::class, function ($mail) use ($accessory, $user) {
+ Mail::assertNotSent(CheckinAccessoryMail::class, function ($mail) use ($accessory, $user) {
return $mail->hasTo($user) && $mail->contains($accessory);
});
}
diff --git a/tests/Feature/Checkouts/Ui/ConsumableCheckoutTest.php b/tests/Feature/Checkouts/Ui/ConsumableCheckoutTest.php
index 76313bb71c..2dc5fa62c0 100644
--- a/tests/Feature/Checkouts/Ui/ConsumableCheckoutTest.php
+++ b/tests/Feature/Checkouts/Ui/ConsumableCheckoutTest.php
@@ -65,7 +65,7 @@ class ConsumableCheckoutTest extends TestCase
'assigned_to' => $user->id,
]);
- Mail::assertNotSent(CheckoutConsumableMail::class, function ($mail) use ($user) {
+ Mail::assertSent(CheckoutConsumableMail::class, function ($mail) use ($user) {
return $mail->hasTo($user->email);
});
}
diff --git a/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php b/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php
index 0b1a1fddc5..098ef184c6 100644
--- a/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php
+++ b/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php
@@ -33,8 +33,8 @@ class EmailNotificationsUponCheckinTest extends TestCase
$this->fireCheckInEvent($asset, $user);
- Mail::assertSent(CheckinAssetMail::class, function($mail) use ($user, $asset) {
- return $mail->hasTo($user->email) && $mail->event->checkoutable->id === $asset->id;
+ Mail::assertSent(CheckinAssetMail::class, function($mail) use ($user) {
+ return $mail->hasTo($user->email);
});
}