From bd03d7093742a721becae41a154ac4050c12a229 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 12 Feb 2025 11:43:22 -0800 Subject: [PATCH] adds test for expiring licenses --- .../Email/ExpiringAlertsNotificationTest.php | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/tests/Feature/Notifications/Email/ExpiringAlertsNotificationTest.php b/tests/Feature/Notifications/Email/ExpiringAlertsNotificationTest.php index a6a6cf5561..2e15100c2b 100644 --- a/tests/Feature/Notifications/Email/ExpiringAlertsNotificationTest.php +++ b/tests/Feature/Notifications/Email/ExpiringAlertsNotificationTest.php @@ -3,6 +3,7 @@ namespace Tests\Feature\Notifications\Email; use App\Mail\ExpiringAssetsMail; +use App\Mail\ExpiringLicenseMail; use App\Models\Asset; use App\Models\License; use App\Models\Setting; @@ -57,7 +58,33 @@ class ExpiringAlertsNotificationTest extends TestCase public function testExpiringLicensesEmailNotification() { Mail::fake(); - $user = User::factory()->create(); - $license = License::factory()->create(); + $this->settings->enableAlertEmail('admin@example.com'); + $this->settings->setAlertInterval(60); + + $alert_email = Setting::first()->alert_email; + + $expiringLicense = License::factory()->create([ + 'expiration_date' => now()->addDays(30)->format('Y-m-d'), + 'deleted_at' => null, + ]); + + $expiredLicense = License::factory()->create([ + 'expiration_date' => now()->subDays(10)->format('Y-m-d'), + 'deleted_at' => null, + ]); + $notExpiringLicense = License::factory()->create([ + 'expiration_date' => now()->addMonths(3)->format('Y-m-d'), + 'deleted_at' => null, + ]); + + $this->artisan('snipeit:expiring-alerts')->assertExitCode(0); + + Mail::assertSent(ExpiringLicenseMail::class, function($mail) use ($alert_email, $expiringLicense) { + return $mail->hasTo($alert_email) && $mail->licenses->contains($expiringLicense); + }); + + Mail::assertNotSent(ExpiringLicenseMail::class, function($mail) use ($expiredLicense, $notExpiringLicense) { + return $mail->licenses->contains($expiredLicense) || $mail->licenses->contains($notExpiringLicense); + }); } } \ No newline at end of file