enableWebhookSettings(); $user = $this->createUser(); $this->createAsset()->checkOut( $user, $this->createSuperUser()->id ); Notification::assertSentTo( new AnonymousNotifiable, CheckoutAssetNotification::class, function ($notification, $channels, $notifiable) { return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint; } ); } public function testNotificationSentToWebhookWhenAssetCheckedOutToAssetAndWebhookNotificationEnabled() { Notification::fake(); $this->enableWebhookSettings(); $this->createAsset()->checkOut( $this->createAsset(), $this->createSuperUser()->id ); // Since the target is not a user with an email address we have // to check if an AnonymousNotifiable was sent. Notification::assertSentTo( new AnonymousNotifiable, CheckoutAssetNotification::class, function ($notification, $channels, $notifiable) { return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint; } ); } public function testDoesNotSendNotificationViaWebhookIfWebHookEndpointIsNotSetWhenCheckingOutAssetToAsset() { Notification::fake(); $this->createAsset()->checkOut( $this->createAsset(), $this->createSuperUser()->id ); Notification::assertNotSentTo( new AnonymousNotifiable, CheckoutAssetNotification::class, ); } public function testNotificationSentToWebhookWhenAssetCheckedOutToLocationAndWebhookNotificationEnabled() { Notification::fake(); $this->enableWebhookSettings(); $this->createAsset()->checkOut( Location::factory()->create(), $this->createSuperUser()->id ); // Since the target is not a user with an email address we have // to check if an AnonymousNotifiable was sent. Notification::assertSentTo( new AnonymousNotifiable, CheckoutAssetNotification::class, function ($notification, $channels, $notifiable) { return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint; } ); } public function testDoesNotSendNotificationViaWebhookIfWebHookEndpointIsNotSetWhenCheckingOutAssetToLocation() { Notification::fake(); $this->createAsset()->checkOut( Location::factory()->create(), $this->createSuperUser()->id ); Notification::assertNotSentTo( new AnonymousNotifiable, 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(); } }