2024-03-14 11:17:47 -07:00
|
|
|
<?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
|
|
|
|
*/
|
2024-03-14 11:17:47 -07:00
|
|
|
class EmailNotificationsUponCheckinTest extends TestCase
|
|
|
|
{
|
2024-03-14 12:02:56 -07:00
|
|
|
protected function setUp(): void
|
2024-03-14 11:17:47 -07:00
|
|
|
{
|
2024-03-14 12:02:56 -07:00
|
|
|
parent::setUp();
|
|
|
|
|
2024-03-14 11:17:47 -07:00
|
|
|
Notification::fake();
|
2024-03-14 12:02:56 -07:00
|
|
|
}
|
2024-03-14 11:17:47 -07:00
|
|
|
|
2024-03-14 12:02:56 -07:00
|
|
|
public function testCheckInEmailSentToUserIfSettingEnabled()
|
|
|
|
{
|
2024-03-14 11:17:47 -07:00
|
|
|
$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-03-14 11:17:47 -07:00
|
|
|
|
|
|
|
Notification::assertSentTo(
|
2024-03-14 12:02:56 -07:00
|
|
|
$user,
|
2024-03-14 11:17:47 -07:00
|
|
|
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);
|
2024-03-14 11:17:47 -07:00
|
|
|
|
|
|
|
Notification::assertNotSentTo(
|
2024-03-14 12:02:56 -07:00
|
|
|
$user,
|
2024-03-14 11:17:47 -07:00
|
|
|
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(),
|
|
|
|
''
|
|
|
|
));
|
|
|
|
}
|
2024-03-14 11:17:47 -07:00
|
|
|
}
|