From 28ced46b9d82745dfcb964c108428ff3d1a1d498 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 22 Mar 2023 12:38:14 -0700 Subject: [PATCH] Clean up test code --- .../AssetCheckoutSlackNotificationTest.php | 57 ++++++++++++------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/tests/Feature/Notifications/AssetCheckoutSlackNotificationTest.php b/tests/Feature/Notifications/AssetCheckoutSlackNotificationTest.php index 784ffb18d0..ac61d4402a 100644 --- a/tests/Feature/Notifications/AssetCheckoutSlackNotificationTest.php +++ b/tests/Feature/Notifications/AssetCheckoutSlackNotificationTest.php @@ -17,14 +17,13 @@ class AssetCheckoutSlackNotificationTest extends TestCase { Notification::fake(); - Setting::factory()->withWebhookEnabled()->create(); + $this->enableWebhookSettings(); - $asset = Asset::factory()->laptopMbp()->create(); - $user = User::factory()->create(); + $user = $this->createUser(); - $asset->checkOut( + $this->createAsset()->checkOut( $user, - User::factory()->superuser()->create()->id + $this->createSuperUser()->id ); Notification::assertSentTo( @@ -40,12 +39,11 @@ class AssetCheckoutSlackNotificationTest extends TestCase { Notification::fake(); - Setting::factory()->withWebhookEnabled()->create(); + $this->enableWebhookSettings(); - $assetBeingCheckedOut = Asset::factory()->laptopMbp()->create(); - $assetBeingCheckedOut->checkOut( - Asset::factory()->laptopMbp()->create(), - User::factory()->superuser()->create()->id + $this->createAsset()->checkOut( + $this->createAsset(), + $this->createSuperUser()->id ); // Since the target is not a user with an email address we have @@ -63,10 +61,9 @@ class AssetCheckoutSlackNotificationTest extends TestCase { Notification::fake(); - $assetBeingCheckedOut = Asset::factory()->laptopMbp()->create(); - $assetBeingCheckedOut->checkOut( - Asset::factory()->laptopMbp()->create(), - User::factory()->superuser()->create()->id + $this->createAsset()->checkOut( + $this->createAsset(), + $this->createSuperUser()->id ); Notification::assertNotSentTo( @@ -79,12 +76,11 @@ class AssetCheckoutSlackNotificationTest extends TestCase { Notification::fake(); - Setting::factory()->withWebhookEnabled()->create(); + $this->enableWebhookSettings(); - $asset = Asset::factory()->laptopMbp()->create(); - $asset->checkOut( + $this->createAsset()->checkOut( Location::factory()->create(), - User::factory()->superuser()->create()->id + $this->createSuperUser()->id ); // Since the target is not a user with an email address we have @@ -102,10 +98,9 @@ class AssetCheckoutSlackNotificationTest extends TestCase { Notification::fake(); - $asset = Asset::factory()->laptopMbp()->create(); - $asset->checkOut( + $this->createAsset()->checkOut( Location::factory()->create(), - User::factory()->superuser()->create()->id + $this->createSuperUser()->id ); Notification::assertNotSentTo( @@ -113,4 +108,24 @@ class AssetCheckoutSlackNotificationTest extends TestCase CheckoutAssetNotification::class, ); } + + private function enableWebhookSettings() + { + Setting::factory()->withWebhookEnabled()->create(); + } + + private function createAsset() + { + return Asset::factory()->laptopMbp()->create(); + } + + private function createUser() + { + return User::factory()->create(); + } + + private function createSuperUser() + { + return User::factory()->superuser()->create(); + } }