2024-03-14 11:17:47 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Notifications\Email;
|
|
|
|
|
2024-10-17 12:05:36 -07:00
|
|
|
use App\Mail\CheckinAssetMail;
|
|
|
|
use Illuminate\Support\Facades\Mail;
|
2024-08-06 13:25:21 -07:00
|
|
|
use PHPUnit\Framework\Attributes\Group;
|
2024-03-14 11:17:47 -07:00
|
|
|
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')]
|
2024-08-06 13:31:17 -07:00
|
|
|
class EmailNotificationsUponCheckinTest extends TestCase
|
2024-03-14 11:17:47 -07:00
|
|
|
{
|
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-10-17 13:34:55 -07:00
|
|
|
Mail::fake();
|
2024-03-14 12:02:56 -07:00
|
|
|
}
|
2024-03-14 11:17:47 -07:00
|
|
|
|
2024-08-06 13:30:34 -07:00
|
|
|
public function testCheckInEmailSentToUserIfSettingEnabled()
|
2024-03-14 12:02:56 -07:00
|
|
|
{
|
2024-10-17 12:05:36 -07:00
|
|
|
Mail::fake();
|
|
|
|
|
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
|
|
|
|
2024-10-22 11:49:06 -07:00
|
|
|
Mail::assertSent(CheckinAssetMail::class, function($mail) use ($user) {
|
|
|
|
return $mail->hasTo($user->email);
|
2024-10-17 12:05:36 -07:00
|
|
|
});
|
|
|
|
|
2024-03-14 11:17:47 -07:00
|
|
|
}
|
|
|
|
|
2024-08-06 13:30:34 -07:00
|
|
|
public function testCheckInEmailNotSentToUserIfSettingDisabled()
|
2024-03-14 11:17:47 -07:00
|
|
|
{
|
2024-10-17 12:05:36 -07:00
|
|
|
Mail::fake();
|
|
|
|
|
2024-03-14 11:17:47 -07:00
|
|
|
$user = User::factory()->create();
|
|
|
|
$asset = Asset::factory()->assignedToUser($user)->create();
|
|
|
|
|
2024-10-24 09:40:10 -07:00
|
|
|
$asset->model->category->update([
|
|
|
|
'checkin_email' => false,
|
|
|
|
'eula_text' => null,
|
|
|
|
'require_acceptance' => false,
|
|
|
|
]);
|
2024-03-14 11:17:47 -07:00
|
|
|
|
2024-03-14 12:02:56 -07:00
|
|
|
$this->fireCheckInEvent($asset, $user);
|
2024-03-14 11:17:47 -07:00
|
|
|
|
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 11:17:47 -07:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
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
|
|
|
}
|