snipe-it/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php

73 lines
1.8 KiB
PHP
Raw Normal View History

<?php
namespace Tests\Feature\Notifications\Email;
use App\Mail\CheckinAssetMail;
use Illuminate\Support\Facades\Mail;
2024-08-06 13:25:21 -07:00
use PHPUnit\Framework\Attributes\Group;
use App\Events\CheckoutableCheckedIn;
use App\Models\Asset;
use App\Models\User;
use App\Notifications\CheckinAssetNotification;
use Illuminate\Support\Facades\Notification;
use Tests\TestCase;
2024-08-06 13:25:21 -07:00
#[Group('notifications')]
class EmailNotificationsUponCheckinTest extends TestCase
{
2024-03-14 12:02:56 -07:00
protected function setUp(): void
{
2024-03-14 12:02:56 -07:00
parent::setUp();
2024-10-17 13:34:55 -07:00
Mail::fake();
2024-03-14 12:02:56 -07:00
}
public function testCheckInEmailSentToUserIfSettingEnabled()
2024-03-14 12:02:56 -07:00
{
Mail::fake();
$user = User::factory()->create();
$asset = Asset::factory()->assignedToUser($user)->create();
$asset->model->category->update(['checkin_email' => true]);
2024-03-14 12:02:56 -07:00
$this->fireCheckInEvent($asset, $user);
2024-10-22 11:49:06 -07:00
Mail::assertSent(CheckinAssetMail::class, function($mail) use ($user) {
return $mail->hasTo($user->email);
});
}
public function testCheckInEmailNotSentToUserIfSettingDisabled()
{
Mail::fake();
$user = User::factory()->create();
$asset = Asset::factory()->assignedToUser($user)->create();
$asset->model->category->update([
'checkin_email' => false,
'eula_text' => null,
'require_acceptance' => false,
]);
2024-03-14 12:02:56 -07:00
$this->fireCheckInEvent($asset, $user);
2024-10-23 17:33:23 -07:00
Mail::assertNotSent(CheckinAssetMail::class, function($mail) use ($user) {
2024-10-23 17:27:37 -07:00
return $mail->hasTo($user->email);
}
);
}
2024-03-14 12:02:56 -07:00
private function fireCheckInEvent($asset, $user): void
{
event(new CheckoutableCheckedIn(
$asset,
$user,
User::factory()->checkinAssets()->create(),
''
));
}
}