A free open source IT asset/license management system
add component notification tests
Godfrey M64d397c3f3a0
diff --git a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.phpindex e2a97c1603..d366103d74 100644--- a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php+++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php@@ -4,6 +4,7 @@ namespace Tests\Feature\Notifications\Webhooks;use App\Models\AssetModel;use App\Models\Category;+use App\Notifications\CheckinComponentNotification;use PHPUnit\Framework\Attributes\DataProvider;use PHPUnit\Framework\Attributes\Group;use App\Events\CheckoutableCheckedIn;@@ -96,6 +97,31 @@ class SlackNotificationsUponCheckinTest extends TestCase$this->assertNoSlackNotificationSent(CheckinAssetNotification::class);}+ #[DataProvider('assetCheckInTargets')]+ public function testComponentCheckinSendsSlackNotificationWhenSettingEnabled($checkoutTarget)+ {+ $this->settings->enableSlackWebhook();++ $this->fireCheckInEvent(+ Component::factory()->create(),+ $checkoutTarget(),+ );++ $this->assertSlackNotificationSent(CheckinComponentNotification::class);+ }++ #[DataProvider('assetCheckInTargets')]+ public function testComponentCheckinDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget)+ {+ $this->settings->disableSlackWebhook();++ $this->fireCheckInEvent(+ Component::factory()->create(),+ $checkoutTarget(),+ );++ $this->assertNoSlackNotificationSent(CheckinComponentNotification::class);+ }public function testSlackNotificationIsStillSentWhenCategoryEmailIsNotSetToSendEmails(){@@ -118,18 +144,6 @@ class SlackNotificationsUponCheckinTest extends TestCase$this->assertSlackNotificationSent(CheckinAssetNotification::class);}- public function testComponentCheckinDoesNotSendSlackNotification()- {- $this->settings->enableSlackWebhook();-- $this->fireCheckInEvent(- Component::factory()->create(),- Asset::factory()->laptopMbp()->create(),- );-- Notification::assertNothingSent();- }-#[DataProvider('licenseCheckInTargets')]public function testLicenseCheckinSendsSlackNotificationWhenSettingEnabled($checkoutTarget){diff --git a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.phpindex c9f426dd30..908acddf3b 100644--- a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php+++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php@@ -4,6 +4,8 @@ namespace Tests\Feature\Notifications\Webhooks;use App\Models\AssetModel;use App\Models\Category;+use App\Notifications\CheckoutComponentNotification;+use Illuminate\Support\Facades\Mail;use PHPUnit\Framework\Attributes\DataProvider;use PHPUnit\Framework\Attributes\Group;use App\Events\CheckoutableCheckedOut;@@ -30,12 +32,13 @@ class SlackNotificationsUponCheckoutTest extends TestCaseparent::setUp();Notification::fake();+ Mail::fake();}public static function assetCheckoutTargets(): array{return [- 'Asset checked out to user' => [fn() => User::factory()->create()],+ 'Asset checked out to user' => [fn() => User::factory()->create(['email' => null])],'Asset checked out to asset' => [fn() => Asset::factory()->laptopMbp()->create()],'Asset checked out to location' => [fn() => Location::factory()->create()],];@@ -44,7 +47,7 @@ class SlackNotificationsUponCheckoutTest extends TestCasepublic static function licenseCheckoutTargets(): array{return [- 'License checked out to user' => [fn() => User::factory()->create()],+ 'License checked out to user' => [fn() => User::factory()->create(['email' => null])],'License checked out to asset' => [fn() => Asset::factory()->laptopMbp()->create()],];}@@ -98,7 +101,41 @@ class SlackNotificationsUponCheckoutTest extends TestCase$this->assertNoSlackNotificationSent(CheckoutAssetNotification::class);}+ #[DataProvider('assetCheckoutTargets')]+ public function testComponentCheckoutSendsSlackNotificationWhenSettingEnabled($checkoutTarget)+ {+ $this->settings->enableSlackWebhook();+ $component = Component::factory()->create([+ 'category_id' => Category::factory()->create([+ 'require_acceptance' => false,+ 'eula_text' => null,+ ]),+ ]);+ $this->fireCheckOutEvent(+ $component,+ $checkoutTarget(),+ );++ $this->assertSlackNotificationSent(CheckoutComponentNotification::class);+ }++ #[DataProvider('assetCheckoutTargets')]+ public function testComponentCheckoutDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget)+ {+ $this->settings->disableSlackWebhook();+ $component = Component::factory()->create([+ 'category_id' => Category::factory()->create([+ 'require_acceptance' => false,+ 'eula_text' => null,+ ]),+ ]);+ $this->fireCheckOutEvent(+ $component,+ $checkoutTarget(),+ );+ $this->assertNoSlackNotificationSent(CheckoutComponentNotification::class);+ }public function testSlackNotificationIsStillSentWhenCategoryEmailIsNotSetToSendEmails(){$this->settings->enableSlackWebhook();@@ -120,18 +157,6 @@ class SlackNotificationsUponCheckoutTest extends TestCase$this->assertSlackNotificationSent(CheckoutAssetNotification::class);}- public function testComponentCheckoutDoesNotSendSlackNotification()- {- $this->settings->enableSlackWebhook();-- $this->fireCheckOutEvent(- Component::factory()->create(),- Asset::factory()->laptopMbp()->create(),- );-- Notification::assertNothingSent();- }-public function testConsumableCheckoutSendsSlackNotificationWhenSettingEnabled(){$this->settings->enableSlackWebhook();