From bf32ab177ff68b2bbe4acbbabc923fe7ed850c76 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 27 Feb 2024 17:37:07 -0800 Subject: [PATCH] Improve readability by extracting fireCheckInEvent method --- .../SlackNotificationsUponCheckinTest.php | 53 +++++++++---------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php index feb4cd26d9..e73d62a1cb 100644 --- a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php +++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php @@ -13,6 +13,7 @@ use App\Models\User; use App\Notifications\CheckinAccessoryNotification; use App\Notifications\CheckinAssetNotification; use App\Notifications\CheckinLicenseSeatNotification; +use Illuminate\Database\Eloquent\Model; use Illuminate\Notifications\AnonymousNotifiable; use Illuminate\Support\Facades\Notification; use Tests\Support\InteractsWithSettings; @@ -50,12 +51,10 @@ class SlackNotificationsUponCheckinTest extends TestCase { $this->settings->enableSlackWebhook(); - event(new CheckoutableCheckedIn( + $this->fireCheckInEvent( Accessory::factory()->appleBtKeyboard()->create(), User::factory()->create(), - User::factory()->superuser()->create(), - '' - )); + ); Notification::assertSentTo( new AnonymousNotifiable, @@ -70,12 +69,10 @@ class SlackNotificationsUponCheckinTest extends TestCase { $this->settings->disableSlackWebhook(); - event(new CheckoutableCheckedIn( + $this->fireCheckInEvent( Accessory::factory()->appleBtKeyboard()->create(), User::factory()->create(), - User::factory()->superuser()->create(), - '' - )); + ); Notification::assertNotSentTo(new AnonymousNotifiable, CheckinAccessoryNotification::class); } @@ -85,12 +82,10 @@ class SlackNotificationsUponCheckinTest extends TestCase { $this->settings->enableSlackWebhook(); - event(new CheckoutableCheckedIn( + $this->fireCheckInEvent( Asset::factory()->laptopMbp()->create(), $checkoutTarget(), - User::factory()->superuser()->create(), - '' - )); + ); Notification::assertSentTo( new AnonymousNotifiable, @@ -106,12 +101,10 @@ class SlackNotificationsUponCheckinTest extends TestCase { $this->settings->disableSlackWebhook(); - event(new CheckoutableCheckedIn( + $this->fireCheckInEvent( Asset::factory()->laptopMbp()->create(), $checkoutTarget(), - User::factory()->superuser()->create(), - '' - )); + ); Notification::assertNotSentTo(new AnonymousNotifiable, CheckinAssetNotification::class); } @@ -120,12 +113,10 @@ class SlackNotificationsUponCheckinTest extends TestCase { $this->settings->enableSlackWebhook(); - event(new CheckoutableCheckedIn( + $this->fireCheckInEvent( Component::factory()->ramCrucial8()->create(), Asset::factory()->laptopMbp()->create(), - User::factory()->superuser()->create(), - '' - )); + ); Notification::assertNothingSent(); } @@ -145,12 +136,10 @@ class SlackNotificationsUponCheckinTest extends TestCase { $this->settings->enableSlackWebhook(); - event(new CheckoutableCheckedIn( + $this->fireCheckInEvent( LicenseSeat::factory()->create(), $checkoutTarget(), - User::factory()->superuser()->create(), - '' - )); + ); Notification::assertSentTo( new AnonymousNotifiable, @@ -166,13 +155,21 @@ class SlackNotificationsUponCheckinTest extends TestCase { $this->settings->disableSlackWebhook(); - event(new CheckoutableCheckedIn( + $this->fireCheckInEvent( LicenseSeat::factory()->create(), $checkoutTarget(), - User::factory()->superuser()->create(), - '' - )); + ); Notification::assertNotSentTo(new AnonymousNotifiable, CheckinLicenseSeatNotification::class); } + + private function fireCheckInEvent(Model $checkoutable, Model $target) + { + event(new CheckoutableCheckedIn( + $checkoutable, + $target, + User::factory()->superuser()->create(), + '' + )); + } }