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

68 lines
1.7 KiB
PHP
Raw Normal View History

<?php
namespace Tests\Feature\Notifications\Email;
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-03-14 11:19:36 -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();
Notification::fake();
2024-03-14 12:02:56 -07:00
}
2024-03-14 12:02:56 -07:00
public function testCheckInEmailSentToUserIfSettingEnabled()
{
$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);
Notification::assertSentTo(
2024-03-14 12:02:56 -07:00
$user,
function (CheckinAssetNotification $notification, $channels) {
return in_array('mail', $channels);
},
);
}
public function testCheckInEmailNotSentToUserIfSettingDisabled()
{
$user = User::factory()->create();
$asset = Asset::factory()->assignedToUser($user)->create();
$asset->model->category->update(['checkin_email' => false]);
2024-03-14 12:02:56 -07:00
$this->fireCheckInEvent($asset, $user);
Notification::assertNotSentTo(
2024-03-14 12:02:56 -07:00
$user,
function (CheckinAssetNotification $notification, $channels) {
return in_array('mail', $channels);
}
);
}
2024-03-14 12:02:56 -07:00
private function fireCheckInEvent($asset, $user): void
{
event(new CheckoutableCheckedIn(
$asset,
$user,
User::factory()->checkinAssets()->create(),
''
));
}
}