Skip to content

Commit 7949069

Browse files
committed
Start Implementing
1 parent a721d11 commit 7949069

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

src/OneSignalChannel.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
class OneSignalChannel
1111
{
12+
1213
/** @var OneSignalClient */
1314
protected $oneSignal;
1415

@@ -20,20 +21,23 @@ public function __construct(OneSignalClient $oneSignal)
2021
/**
2122
* Send the given notification.
2223
*
23-
* @param mixed $notifiable
24+
* @param mixed $notifiable
2425
* @param \Illuminate\Notifications\Notification $notification
2526
*
2627
* @throws \NotificationChannels\OneSignal\Exceptions\CouldNotSendNotification
2728
*/
2829
public function send($notifiable, Notification $notification)
2930
{
30-
if (! $userIds = $notifiable->routeNotificationFor('OneSignal')) {
31+
if (!$userIds = $notifiable->routeNotificationFor('OneSignal')) {
3132
return;
3233
}
3334

3435
$payload = $notification->toOneSignal($notifiable)->toArray();
35-
$payload['include_player_ids'] = collect($userIds);
36-
36+
if (is_array($userIds) && array_key_exists('email', $userIds)) {
37+
$payload['tags'] = collect(["key" => "email", "relation" => "=", "value" => $userIds['email']]);
38+
} else {
39+
$payload['include_player_ids'] = collect($userIds);
40+
}
3741
/** @var ResponseInterface $response */
3842
$response = $this->oneSignal->sendNotificationCustom($payload);
3943

tests/ChannelTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
class ChannelTest extends TestCase
1313
{
14+
1415
/** @var Mockery\Mock */
1516
protected $oneSignal;
1617

@@ -80,4 +81,27 @@ public function it_throws_an_exception_when_it_could_not_send_the_notification()
8081

8182
$this->channel->send(new Notifiable(), new TestNotification());
8283
}
84+
85+
public function it_can_send_a_notification_with_email()
86+
{
87+
$response = new Response(200);
88+
89+
$this->oneSignal->shouldReceive('sendNotificationCustom')
90+
->once()
91+
->with([
92+
'contents' => ['en' => 'Body'],
93+
'headings' => ['en' => 'Subject'],
94+
'url' => 'URL',
95+
'buttons' => [],
96+
'web_buttons' => [],
97+
'chrome_web_icon' => 'Icon',
98+
'chrome_icon' => 'Icon',
99+
'adm_small_icon' => 'Icon',
100+
'small_icon' => 'Icon',
101+
'tags' => collect(["key" => "email", "relation" => "=", "value" => '[email protected]']),
102+
])
103+
->andReturn($response);
104+
105+
$this->channel->send(new NotifiableEMail(), new TestNotification());
106+
}
83107
}

tests/NotifiableEMail.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 NotifiableEMail
6+
{
7+
use \Illuminate\Notifications\Notifiable;
8+
9+
/**
10+
* @return int
11+
*/
12+
public function routeNotificationForOneSignal()
13+
{
14+
return ['email' => '[email protected]'];
15+
}
16+
}

0 commit comments

Comments
 (0)