mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
adds test for expiring licenses
This commit is contained in:
parent
6873244e7e
commit
bd03d70937
|
@ -3,6 +3,7 @@
|
||||||
namespace Tests\Feature\Notifications\Email;
|
namespace Tests\Feature\Notifications\Email;
|
||||||
|
|
||||||
use App\Mail\ExpiringAssetsMail;
|
use App\Mail\ExpiringAssetsMail;
|
||||||
|
use App\Mail\ExpiringLicenseMail;
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
use App\Models\License;
|
use App\Models\License;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
|
@ -57,7 +58,33 @@ class ExpiringAlertsNotificationTest extends TestCase
|
||||||
public function testExpiringLicensesEmailNotification()
|
public function testExpiringLicensesEmailNotification()
|
||||||
{
|
{
|
||||||
Mail::fake();
|
Mail::fake();
|
||||||
$user = User::factory()->create();
|
$this->settings->enableAlertEmail('admin@example.com');
|
||||||
$license = License::factory()->create();
|
$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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue