Ensure CC emails are always sent for assets
This commit is contained in:
@@ -399,6 +399,10 @@ class CheckoutableListener
|
||||
|
||||
private function shouldSendEmailNotifications($checkoutable): bool
|
||||
{
|
||||
if (Setting::getSettings()->admin_cc_email) {
|
||||
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,
|
||||
|
||||
@@ -4,6 +4,8 @@ namespace Tests\Feature\Notifications\Email;
|
||||
|
||||
use App\Mail\CheckinAssetMail;
|
||||
use App\Models\Accessory;
|
||||
use App\Models\AssetModel;
|
||||
use App\Models\Category;
|
||||
use App\Models\Consumable;
|
||||
use App\Models\LicenseSeat;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
@@ -93,7 +95,17 @@ class EmailNotificationsUponCheckinTest extends TestCase
|
||||
|
||||
public function testAdminCCEmailStillSentWhenCategoryEmailIsNotSetToSendEmailToUser()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
$this->settings->enableAdminCC('cc@example.com');
|
||||
|
||||
$category = Category::factory()->create(['checkin_email' => false]);
|
||||
$assetModel = AssetModel::factory()->create(['category_id' => $category->id]);
|
||||
$asset = Asset::factory()->create(['model_id' => $assetModel->id]);
|
||||
|
||||
$this->fireCheckInEvent($asset, User::factory()->create());
|
||||
|
||||
Mail::assertSent(CheckinAssetMail::class, function ($mail) {
|
||||
return $mail->hasTo('cc@example.com');
|
||||
});
|
||||
}
|
||||
|
||||
private function fireCheckInEvent($asset, $user): void
|
||||
|
||||
@@ -2,14 +2,44 @@
|
||||
|
||||
namespace Tests\Feature\Notifications\Email;
|
||||
|
||||
use App\Events\CheckoutableCheckedOut;
|
||||
use App\Mail\CheckinAssetMail;
|
||||
use App\Mail\CheckoutAssetMail;
|
||||
use App\Models\Asset;
|
||||
use App\Models\AssetModel;
|
||||
use App\Models\Category;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
use Tests\TestCase;
|
||||
|
||||
#[Group('notifications')]
|
||||
class EmailNotificationsUponCheckoutTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Mail::fake();
|
||||
}
|
||||
|
||||
public function testAdminCCEmailStillSentWhenCategoryEmailIsNotSetToSendEmailToUser()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
$this->settings->enableAdminCC('cc@example.com');
|
||||
|
||||
$category = Category::factory()->create(['checkin_email' => false]);
|
||||
$assetModel = AssetModel::factory()->create(['category_id' => $category->id]);
|
||||
$asset = Asset::factory()->create(['model_id' => $assetModel->id]);
|
||||
|
||||
event(new CheckoutableCheckedOut(
|
||||
$asset,
|
||||
User::factory()->create(),
|
||||
User::factory()->superuser()->create(),
|
||||
'',
|
||||
));
|
||||
|
||||
Mail::assertSent(CheckoutAssetMail::class, function ($mail) {
|
||||
return $mail->hasTo('cc@example.com');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,13 @@ class Settings
|
||||
]);
|
||||
}
|
||||
|
||||
public function enableAdminCC(string $email = 'cc@example.co'): Settings
|
||||
{
|
||||
return $this->update([
|
||||
'admin_cc_email' => $email,
|
||||
]);
|
||||
}
|
||||
|
||||
public function disableAdminCC(): Settings
|
||||
{
|
||||
return $this->update([
|
||||
|
||||
Reference in New Issue
Block a user