[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()], ]; } public static function licenseCheckoutTargets(): array { return [ 'License checked out to user' => [fn () => User::factory()->create(['email' => null])], 'License checked out to asset' => [fn () => Asset::factory()->laptopMbp()->create()], ]; } public function test_accessory_checkout_sends_slack_notification_when_setting_enabled() { $this->settings->enableSlackWebhook(); $this->fireCheckOutEvent( Accessory::factory()->create(), User::factory()->create(), ); $this->assertSlackNotificationSent(CheckoutAccessoryNotification::class); } public function test_accessory_checkout_does_not_send_slack_notification_when_setting_disabled() { $this->settings->disableSlackWebhook(); $this->fireCheckOutEvent( Accessory::factory()->create(), User::factory()->create(), ); $this->assertNoSlackNotificationSent(CheckoutAccessoryNotification::class); } #[DataProvider('assetCheckoutTargets')] public function test_asset_checkout_sends_slack_notification_when_setting_enabled($checkoutTarget) { $this->settings->enableSlackWebhook(); $this->fireCheckOutEvent( Asset::factory()->create(), $checkoutTarget(), ); $this->assertSlackNotificationSent(CheckoutAssetNotification::class); } #[DataProvider('assetCheckoutTargets')] public function test_asset_checkout_does_not_send_slack_notification_when_setting_disabled($checkoutTarget) { $this->settings->disableSlackWebhook(); $this->fireCheckOutEvent( Asset::factory()->create(), $checkoutTarget(), ); $this->assertNoSlackNotificationSent(CheckoutAssetNotification::class); } #[DataProvider('assetCheckoutTargets')] public function test_component_checkout_sends_slack_notification_when_setting_enabled($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 test_component_checkout_does_not_send_slack_notification_when_setting_disabled($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 test_slack_notification_is_still_sent_when_category_email_is_not_set_to_send_emails() { $this->settings->enableSlackWebhook(); $category = Category::factory()->create([ 'checkin_email' => false, 'eula_text' => null, 'require_acceptance' => false, 'use_default_eula' => false, ]); $assetModel = AssetModel::factory()->for($category)->create(); $asset = Asset::factory()->for($assetModel, 'model')->create(); $this->fireCheckOutEvent( $asset, User::factory()->create(), ); $this->assertSlackNotificationSent(CheckoutAssetNotification::class); } public function test_consumable_checkout_sends_slack_notification_when_setting_enabled() { $this->settings->enableSlackWebhook(); $this->fireCheckOutEvent( Consumable::factory()->create(), User::factory()->create(), ); $this->assertSlackNotificationSent(CheckoutConsumableNotification::class); } public function test_consumable_checkout_does_not_send_slack_notification_when_setting_disabled() { $this->settings->disableSlackWebhook(); $this->fireCheckOutEvent( Consumable::factory()->create(), User::factory()->create(), ); $this->assertNoSlackNotificationSent(CheckoutConsumableNotification::class); } #[DataProvider('licenseCheckoutTargets')] public function test_license_checkout_sends_slack_notification_when_setting_enabled($checkoutTarget) { $this->settings->enableSlackWebhook(); $this->fireCheckOutEvent( LicenseSeat::factory()->create(), $checkoutTarget(), ); $this->assertSlackNotificationSent(CheckoutLicenseSeatNotification::class); } #[DataProvider('licenseCheckoutTargets')] public function test_license_checkout_does_not_send_slack_notification_when_setting_disabled($checkoutTarget) { $this->settings->disableSlackWebhook(); $this->fireCheckOutEvent( LicenseSeat::factory()->create(), $checkoutTarget(), ); $this->assertNoSlackNotificationSent(CheckoutLicenseSeatNotification::class); } private function fireCheckOutEvent(Model $checkoutable, Model $target) { event(new CheckoutableCheckedOut( $checkoutable, $target, User::factory()->superuser()->create(), '', )); } }