Skip to content

Commit

Permalink
Merge pull request #46 from pavoltanuska/patch-1
Browse files Browse the repository at this point in the history
Return the response after sending the message
  • Loading branch information
Lloople authored Feb 9, 2018
2 parents dc1ae9b + e690872 commit 58ebf2c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/OneSignalChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function __construct(OneSignalClient $oneSignal)
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
*
* @return \Psr\Http\Message\ResponseInterface
* @throws \NotificationChannels\OneSignal\Exceptions\CouldNotSendNotification
*/
public function send($notifiable, Notification $notification)
Expand All @@ -45,5 +46,7 @@ public function send($notifiable, Notification $notification)
if ($response->getStatusCode() !== 200) {
throw CouldNotSendNotification::serviceRespondedWithAnError($response);
}

return $response;
}
}
19 changes: 17 additions & 2 deletions tests/ChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use GuzzleHttp\Psr7\Response;
use Orchestra\Testbench\TestCase;
use Berkayk\OneSignal\OneSignalClient;
use Psr\Http\Message\ResponseInterface;
use NotificationChannels\OneSignal\OneSignalChannel;
use NotificationChannels\OneSignal\Exceptions\CouldNotSendNotification;

Expand Down Expand Up @@ -52,7 +53,9 @@ public function it_can_send_a_notification()
])
->andReturn($response);

$this->channel->send(new Notifiable(), new TestNotification());
$channel_response = $this->channel->send(new Notifiable(), new TestNotification());

$this->assertInstanceOf(ResponseInterface::class, $channel_response);
}

/** @test */
Expand Down Expand Up @@ -104,6 +107,18 @@ public function it_can_send_a_notification_with_email()
])
->andReturn($response);

$this->channel->send(new NotifiableEmail(), new TestNotification());
$channel_response = $this->channel->send(new NotifiableEmail(), new TestNotification());

$this->assertInstanceOf(ResponseInterface::class, $channel_response);
}

/** @test */
public function it_sends_nothing_and_returns_null_when_player_id_empty()
{
$this->oneSignal->shouldReceive('sendNotificationCustom')
->never();

$channel_response = $this->channel->send(new EmptyNotifiable(), new TestNotification());
$this->assertNull($channel_response);
}
}
16 changes: 16 additions & 0 deletions tests/EmptyNotifiable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace NotificationChannels\OneSignal\Test;

class EmptyNotifiable
{
use \Illuminate\Notifications\Notifiable;

/**
* @return int
*/
public function routeNotificationForOneSignal()
{
return '';
}
}

0 comments on commit 58ebf2c

Please sign in to comment.