Skip to content

A free open source IT asset/license management system

Add scenario

Marcus Moore6307337892a6
diff --git a/app/Listeners/CheckoutablesCheckedOutInBulkListener.php b/app/Listeners/CheckoutablesCheckedOutInBulkListener.php
index bd0b395b7a..29f943f536 100644
--- a/app/Listeners/CheckoutablesCheckedOutInBulkListener.php
+++ b/app/Listeners/CheckoutablesCheckedOutInBulkListener.php
@@ -22,7 +22,7 @@ class CheckoutablesCheckedOutInBulkListener
public function handle(CheckoutablesCheckedOutInBulk $event): void
{
$shouldSendEmailToUser = $this->shouldSendCheckoutEmailToUser($event->assets);
- $shouldSendEmailToAlertAddress = $this->shouldSendEmailToAlertAddress();
+ $shouldSendEmailToAlertAddress = $this->shouldSendEmailToAlertAddress($event->assets);
if ($shouldSendEmailToUser && $event->target->email) {
Mail::to($event->target)->send(new BulkAssetCheckoutMail(
@@ -54,7 +54,7 @@ class CheckoutablesCheckedOutInBulkListener
return $this->requiresAcceptance($assets);
}
- private function shouldSendEmailToAlertAddress(): bool
+ private function shouldSendEmailToAlertAddress(Collection $assets): bool
{
$setting = Setting::getSettings();
@@ -66,6 +66,10 @@ class CheckoutablesCheckedOutInBulkListener
return true;
}
+ if (!$this->requiresAcceptance($assets)) {
+ return false;
+ }
+
return (bool) $setting->admin_cc_email;
}
diff --git a/tests/Feature/Notifications/Email/BulkCheckoutEmailTest.php b/tests/Feature/Notifications/Email/BulkCheckoutEmailTest.php
index a2135c1a6f..3b938b797a 100644
--- a/tests/Feature/Notifications/Email/BulkCheckoutEmailTest.php
+++ b/tests/Feature/Notifications/Email/BulkCheckoutEmailTest.php
@@ -16,7 +16,6 @@ class BulkCheckoutEmailTest extends TestCase
private $target;
private $admin;
private $checkout_at;
- private $expected_checkin;
protected function setUp(): void
{
@@ -30,7 +29,6 @@ class BulkCheckoutEmailTest extends TestCase
$this->target = User::factory()->create(['email' => '[email protected]']);
$this->admin = User::factory()->create();
$this->checkout_at = date('Y-m-d H:i:s');
- $this->expected_checkin = '';
}
public function test_email_is_sent_to_user()
@@ -46,18 +44,17 @@ class BulkCheckoutEmailTest extends TestCase
});
}
- public function test_email_is_not_sent_when_user_does_not_have_email_address()
+ public function test_email_is_not_sent_to_user_when_user_does_not_have_email_address()
{
$this->target = User::factory()->create(['email' => null]);
$this->dispatchEvent();
Mail::assertNotSent(CheckoutAssetMail::class);
-
Mail::assertNotSent(BulkAssetCheckoutMail::class);
}
- public function test_email_is_not_sent_if_assets_do_not_require_acceptance()
+ public function test_email_is_not_sent_to_user_if_assets_do_not_require_acceptance()
{
$this->assets = Asset::factory()->count(2)->create();
@@ -86,7 +83,20 @@ class BulkCheckoutEmailTest extends TestCase
});
}
- public function test_email_is_sent_to_cc_address_when_admin_cc_always_enabled()
+ public function test_email_is_not_sent_to_cc_address_when_assets_do_not_require_acceptance()
+ {
+ $this->settings->enableAdminCC('[email protected]');
+ $this->settings->disableAdminCCAlways();
+
+ $this->assets = Asset::factory()->count(2)->create();
+
+ $this->dispatchEvent();
+
+ Mail::assertNotSent(CheckoutAssetMail::class);
+ Mail::assertNotSent(BulkAssetCheckoutMail::class);
+ }
+
+ public function test_email_is_sent_to_cc_address_when_assets_do_not_require_acceptance_but_admin_cc_always_enabled()
{
$this->settings->enableAdminCC('[email protected]');
$this->settings->enableAdminCCAlways();
@@ -97,6 +107,8 @@ class BulkCheckoutEmailTest extends TestCase
Mail::assertNotSent(CheckoutAssetMail::class);
+ Mail::assertSent(BulkAssetCheckoutMail::class, 1);
+
Mail::assertSent(BulkAssetCheckoutMail::class, function (BulkAssetCheckoutMail $mail) {
return $mail->hasTo('[email protected]');
});
@@ -109,7 +121,7 @@ class BulkCheckoutEmailTest extends TestCase
$this->target,
$this->admin,
$this->checkout_at,
- $this->expected_checkin,
+ '',
'A note here',
);
}