Skip to content

Commit 58ebf2c

Browse files
authored
Merge pull request #46 from pavoltanuska/patch-1
Return the response after sending the message
2 parents dc1ae9b + e690872 commit 58ebf2c

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

src/OneSignalChannel.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function __construct(OneSignalClient $oneSignal)
2323
* @param mixed $notifiable
2424
* @param \Illuminate\Notifications\Notification $notification
2525
*
26+
* @return \Psr\Http\Message\ResponseInterface
2627
* @throws \NotificationChannels\OneSignal\Exceptions\CouldNotSendNotification
2728
*/
2829
public function send($notifiable, Notification $notification)
@@ -45,5 +46,7 @@ public function send($notifiable, Notification $notification)
4546
if ($response->getStatusCode() !== 200) {
4647
throw CouldNotSendNotification::serviceRespondedWithAnError($response);
4748
}
49+
50+
return $response;
4851
}
4952
}

tests/ChannelTest.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use GuzzleHttp\Psr7\Response;
77
use Orchestra\Testbench\TestCase;
88
use Berkayk\OneSignal\OneSignalClient;
9+
use Psr\Http\Message\ResponseInterface;
910
use NotificationChannels\OneSignal\OneSignalChannel;
1011
use NotificationChannels\OneSignal\Exceptions\CouldNotSendNotification;
1112

@@ -52,7 +53,9 @@ public function it_can_send_a_notification()
5253
])
5354
->andReturn($response);
5455

55-
$this->channel->send(new Notifiable(), new TestNotification());
56+
$channel_response = $this->channel->send(new Notifiable(), new TestNotification());
57+
58+
$this->assertInstanceOf(ResponseInterface::class, $channel_response);
5659
}
5760

5861
/** @test */
@@ -104,6 +107,18 @@ public function it_can_send_a_notification_with_email()
104107
])
105108
->andReturn($response);
106109

107-
$this->channel->send(new NotifiableEmail(), new TestNotification());
110+
$channel_response = $this->channel->send(new NotifiableEmail(), new TestNotification());
111+
112+
$this->assertInstanceOf(ResponseInterface::class, $channel_response);
113+
}
114+
115+
/** @test */
116+
public function it_sends_nothing_and_returns_null_when_player_id_empty()
117+
{
118+
$this->oneSignal->shouldReceive('sendNotificationCustom')
119+
->never();
120+
121+
$channel_response = $this->channel->send(new EmptyNotifiable(), new TestNotification());
122+
$this->assertNull($channel_response);
108123
}
109124
}

tests/EmptyNotifiable.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace NotificationChannels\OneSignal\Test;
4+
5+
class EmptyNotifiable
6+
{
7+
use \Illuminate\Notifications\Notifiable;
8+
9+
/**
10+
* @return int
11+
*/
12+
public function routeNotificationForOneSignal()
13+
{
14+
return '';
15+
}
16+
}

0 commit comments

Comments
 (0)