Move notification test to notifications test suite

This commit is contained in:
Marcus Moore 2024-02-14 11:16:31 -08:00
parent 4354e126b1
commit 3cc72021b6
No known key found for this signature in database
3 changed files with 48 additions and 60 deletions

View file

@ -120,14 +120,4 @@ class AssetCheckinTest extends TestCase
{ {
$this->markTestIncomplete(); $this->markTestIncomplete();
} }
public function testCheckInEmailSentToUserIfSettingEnabled()
{
$this->markTestIncomplete();
}
public function testCheckInEmailNotSentToUserIfSettingDisabled()
{
$this->markTestIncomplete();
}
} }

View file

@ -9,9 +9,7 @@ use App\Models\LicenseSeat;
use App\Models\Location; use App\Models\Location;
use App\Models\Statuslabel; use App\Models\Statuslabel;
use App\Models\User; use App\Models\User;
use App\Notifications\CheckinAssetNotification;
use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Notification;
use Tests\Support\InteractsWithSettings; use Tests\Support\InteractsWithSettings;
use Tests\TestCase; use Tests\TestCase;
@ -169,52 +167,4 @@ class AssetCheckinTest extends TestCase
return $event->action_date === '2023-01-02 12:45:56' && $event->note === 'hello'; return $event->action_date === '2023-01-02 12:45:56' && $event->note === 'hello';
}, 1); }, 1);
} }
public function testCheckInEmailSentToUserIfSettingEnabled()
{
Notification::fake();
$user = User::factory()->create();
$asset = Asset::factory()->assignedToUser($user)->create();
$asset->model->category->update(['checkin_email' => true]);
event(new CheckoutableCheckedIn(
$asset,
$user,
User::factory()->checkinAssets()->create(),
''
));
Notification::assertSentTo(
[$user],
function (CheckinAssetNotification $notification, $channels) {
return in_array('mail', $channels);
},
);
}
public function testCheckInEmailNotSentToUserIfSettingDisabled()
{
Notification::fake();
$user = User::factory()->create();
$asset = Asset::factory()->assignedToUser($user)->create();
$asset->model->category->update(['checkin_email' => false]);
event(new CheckoutableCheckedIn(
$asset,
$user,
User::factory()->checkinAssets()->create(),
''
));
Notification::assertNotSentTo(
[$user],
function (CheckinAssetNotification $notification, $channels) {
return in_array('mail', $channels);
}
);
}
} }

View file

@ -108,6 +108,54 @@ class AssetWebhookTest extends TestCase
Notification::assertNotSentTo(new AnonymousNotifiable, CheckinAssetNotification::class); Notification::assertNotSentTo(new AnonymousNotifiable, CheckinAssetNotification::class);
} }
public function testCheckInEmailSentToUserIfSettingEnabled()
{
Notification::fake();
$user = User::factory()->create();
$asset = Asset::factory()->assignedToUser($user)->create();
$asset->model->category->update(['checkin_email' => true]);
event(new CheckoutableCheckedIn(
$asset,
$user,
User::factory()->checkinAssets()->create(),
''
));
Notification::assertSentTo(
[$user],
function (CheckinAssetNotification $notification, $channels) {
return in_array('mail', $channels);
},
);
}
public function testCheckInEmailNotSentToUserIfSettingDisabled()
{
Notification::fake();
$user = User::factory()->create();
$asset = Asset::factory()->assignedToUser($user)->create();
$asset->model->category->update(['checkin_email' => false]);
event(new CheckoutableCheckedIn(
$asset,
$user,
User::factory()->checkinAssets()->create(),
''
));
Notification::assertNotSentTo(
[$user],
function (CheckinAssetNotification $notification, $channels) {
return in_array('mail', $channels);
}
);
}
private function createAsset() private function createAsset()
{ {
return Asset::factory()->laptopMbp()->create(); return Asset::factory()->laptopMbp()->create();