[fn() => User::factory()->create()], 'Asset checked out to asset' => [fn() => Asset::factory()->laptopMbp()->create()], 'Asset checked out to location' => [fn() => Location::factory()->create()], ]; } public static function licenseCheckInTargets(): array { return [ 'License checked out to user' => [fn() => User::factory()->create()], 'License checked out to asset' => [fn() => Asset::factory()->laptopMbp()->create()], ]; } public function testAccessoryCheckinSendsSlackNotificationWhenSettingEnabled() { $this->settings->enableSlackWebhook(); $this->fireCheckInEvent( Accessory::factory()->create(), User::factory()->create(), ); $this->assertSlackNotificationSent(CheckinAccessoryNotification::class); } public function testAccessoryCheckinDoesNotSendSlackNotificationWhenSettingDisabled() { $this->settings->disableSlackWebhook(); $this->fireCheckInEvent( Accessory::factory()->create(), User::factory()->create(), ); $this->assertNoSlackNotificationSent(CheckinAccessoryNotification::class); } #[DataProvider('assetCheckInTargets')] public function testAssetCheckinSendsSlackNotificationWhenSettingEnabled($checkoutTarget) { $this->settings->enableSlackWebhook(); $this->fireCheckInEvent( Asset::factory()->create(), $checkoutTarget(), ); $this->assertSlackNotificationSent(CheckinAssetNotification::class); } #[DataProvider('assetCheckInTargets')] public function testAssetCheckinDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget) { $this->settings->disableSlackWebhook(); $this->fireCheckInEvent( Asset::factory()->create(), $checkoutTarget(), ); $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() { $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')->assignedToUser()->create(); $this->fireCheckInEvent( $asset, User::factory()->create(), ); $this->assertSlackNotificationSent(CheckinAssetNotification::class); } #[DataProvider('licenseCheckInTargets')] public function testLicenseCheckinSendsSlackNotificationWhenSettingEnabled($checkoutTarget) { $this->settings->enableSlackWebhook(); $this->fireCheckInEvent( LicenseSeat::factory()->create(), $checkoutTarget(), ); $this->assertSlackNotificationSent(CheckinLicenseSeatNotification::class); } #[DataProvider('licenseCheckInTargets')] public function testLicenseCheckinDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget) { $this->settings->disableSlackWebhook(); $this->fireCheckInEvent( LicenseSeat::factory()->create(), $checkoutTarget(), ); $this->assertNoSlackNotificationSent(CheckinLicenseSeatNotification::class); } private function fireCheckInEvent(Model $checkoutable, Model $target) { event(new CheckoutableCheckedIn( $checkoutable, $target, User::factory()->superuser()->create(), '' )); } }