diff --git a/src/OneSignalMessage.php b/src/OneSignalMessage.php index 305a81e..af21d72 100644 --- a/src/OneSignalMessage.php +++ b/src/OneSignalMessage.php @@ -4,14 +4,14 @@ use Illuminate\Support\Arr; use NotificationChannels\OneSignal\Traits\{ - Categories\AppearanceHelpers, Categories\AttachmentHelpers, Categories\ButtonHelpers, Categories\DeliveryHelpers, Categories\GroupingHelpers, Deprecated + Categories\AppearanceHelpers, Categories\AttachmentHelpers, Categories\ButtonHelpers, Categories\DeliveryHelpers, Categories\GroupingHelpers, Categories\SilentHelpers, Deprecated }; class OneSignalMessage { - use AppearanceHelpers, AttachmentHelpers, ButtonHelpers, DeliveryHelpers, GroupingHelpers, Deprecated; + use AppearanceHelpers, AttachmentHelpers, ButtonHelpers, DeliveryHelpers, GroupingHelpers, SilentHelpers, Deprecated; /** @var array */ protected $payload = []; diff --git a/src/Traits/Categories/SilentHelpers.php b/src/Traits/Categories/SilentHelpers.php new file mode 100644 index 0000000..384e897 --- /dev/null +++ b/src/Traits/Categories/SilentHelpers.php @@ -0,0 +1,18 @@ +payload, 'contents'); //removes any contents that are set by constructor. + return $this->setParameter('content_available', 1); + } +} diff --git a/tests/ChannelTest.php b/tests/ChannelTest.php index 68697e6..6f70008 100644 --- a/tests/ChannelTest.php +++ b/tests/ChannelTest.php @@ -165,4 +165,23 @@ public function it_sends_nothing_and_returns_null_when_player_id_empty() $channel_response = $this->channel->send(new EmptyNotifiable(), new TestNotification()); $this->assertNull($channel_response); } + + public function it_can_send_a_silent_notification() + { + $response = new Response(200); + + $this->oneSignal->shouldReceive('sendNotificationCustom') + ->once() + ->with([ + 'content_available' => 1, + 'data.action' => 'reload', + 'data.target' => 'inbox', + 'include_player_ids' => collect('player_id'), + ]) + ->andReturn($response); + + $channel_response = $this->channel->send(new Notifiable(), new TestSilentNotification()); + + $this->assertInstanceOf(ResponseInterface::class, $channel_response); + } } diff --git a/tests/TestSilentNotification.php b/tests/TestSilentNotification.php new file mode 100644 index 0000000..185ddc1 --- /dev/null +++ b/tests/TestSilentNotification.php @@ -0,0 +1,17 @@ +setSilent() + ->setData('action', 'reload') + ->setData('target', 'inbox'); + } +}