[fn() => User::factory()->create()], 'Asset checked out to asset' => [fn() => Asset::factory()->laptopMbp()->create()], 'Asset checked out to location' => [fn() => Location::factory()->create()], ]; } public function licenseCheckoutTargets(): array { return [ 'License checked out to user' => [fn() => User::factory()->create()], 'License checked out to asset' => [fn() => Asset::factory()->laptopMbp()->create()], ]; } public function testAccessoryCheckoutSendsSlackNotificationWhenSettingEnabled() { $this->settings->enableSlackWebhook(); event(new CheckoutableCheckedOut( Accessory::factory()->appleBtKeyboard()->create(), User::factory()->create(), User::factory()->superuser()->create(), '' )); Notification::assertSentTo( new AnonymousNotifiable, CheckoutAccessoryNotification::class, function ($notification, $channels, $notifiable) { return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint; } ); } public function testAccessoryCheckoutDoesNotSendSlackNotificationWhenSettingDisabled() { $this->settings->disableSlackWebhook(); event(new CheckoutableCheckedOut( Accessory::factory()->appleBtKeyboard()->create(), User::factory()->create(), User::factory()->superuser()->create(), '' )); Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAccessoryNotification::class); } /** @dataProvider assetCheckoutTargets */ public function testAssetCheckoutSendsSlackNotificationWhenSettingEnabled($checkoutTarget) { $this->settings->enableSlackWebhook(); event(new CheckoutableCheckedOut( Asset::factory()->laptopMbp()->create(), $checkoutTarget(), User::factory()->superuser()->create(), '' )); Notification::assertSentTo( new AnonymousNotifiable, CheckoutAssetNotification::class, function ($notification, $channels, $notifiable) { return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint; } ); } /** @dataProvider assetCheckoutTargets */ public function testAssetCheckoutDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget) { $this->settings->disableSlackWebhook(); event(new CheckoutableCheckedOut( Asset::factory()->laptopMbp()->create(), $checkoutTarget(), User::factory()->superuser()->create(), '' )); Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAssetNotification::class); } public function testComponentCheckoutDoesNotSendSlackNotification() { $this->settings->enableSlackWebhook(); event(new CheckoutableCheckedOut( Component::factory()->ramCrucial8()->create(), Asset::factory()->laptopMbp()->create(), User::factory()->superuser()->create(), '' )); Notification::assertNothingSent(); } public function testConsumableCheckoutSendsSlackNotificationWhenSettingEnabled() { $this->settings->enableSlackWebhook(); event(new CheckoutableCheckedOut( Consumable::factory()->cardstock()->create(), User::factory()->create(), User::factory()->superuser()->create(), '' )); Notification::assertSentTo( new AnonymousNotifiable, CheckoutConsumableNotification::class, function ($notification, $channels, $notifiable) { return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint; } ); } public function testConsumableCheckoutDoesNotSendSlackNotificationWhenSettingDisabled() { $this->settings->disableSlackWebhook(); event(new CheckoutableCheckedOut( Consumable::factory()->cardstock()->create(), User::factory()->create(), User::factory()->superuser()->create(), '' )); Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutConsumableNotification::class); } /** @dataProvider licenseCheckoutTargets */ public function testLicenseCheckoutSendsSlackNotificationWhenSettingEnabled($checkoutTarget) { $this->settings->enableSlackWebhook(); event(new CheckoutableCheckedOut( LicenseSeat::factory()->create(), $checkoutTarget(), User::factory()->superuser()->create(), '' )); Notification::assertSentTo( new AnonymousNotifiable, CheckoutLicenseSeatNotification::class, function ($notification, $channels, $notifiable) { return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint; } ); } /** @dataProvider licenseCheckoutTargets */ public function testLicenseCheckoutDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget) { $this->settings->disableSlackWebhook(); event(new CheckoutableCheckedOut( LicenseSeat::factory()->create(), $checkoutTarget(), User::factory()->superuser()->create(), '' )); Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutLicenseSeatNotification::class); } }