Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ability of user to send notification , filtering for multiple tags #73

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/OneSignalPayloadFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,18 @@ public static function make($notifiable, Notification $notification, $targeting)
if (static::isTargetingEmail($targeting)) {
$payload['filters'] = collect([['field' => 'email', 'value' => $targeting['email']]]);
} elseif (static::isTargetingTags($targeting)) {
$payload['tags'] = collect([$targeting['tags']]);
$array = $targeting['tags'];
$res = count($array) == count($array, COUNT_RECURSIVE);
if ($res) {
$payload['tags'] = collect([$targeting['tags']]);
} else {
$payload['tags'] = collect($targeting['tags']);
}
} elseif (static::isTargetingIncludedSegments($targeting)) {
$payload['included_segments'] = collect($targeting['included_segments']);
} elseif (static::isTargetingExcludedSegments($targeting)) {
$payload['excluded_segments'] = collect($targeting['excluded_segments']);

} else {
$payload['include_player_ids'] = collect($targeting);
}
Expand Down
27 changes: 27 additions & 0 deletions tests/ChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,33 @@ public function it_can_send_a_notification_with_tags()
$this->assertInstanceOf(ResponseInterface::class, $channel_response);
}

/** @test */
public function it_can_send_a_notification_with_multiple_tags()
{
$response = new Response(200);

$this->oneSignal->shouldReceive('sendNotificationCustom')
->once()
->with([
'contents' => ['en' => 'Body'],
'headings' => ['en' => 'Subject'],
'url' => 'URL',
'chrome_web_icon' => 'Icon',
'chrome_icon' => 'Icon',
'adm_small_icon' => 'Icon',
'small_icon' => 'Icon',
'tags' => collect([
['key' => 'device_uuid', 'relation' => '=', 'value' => '123e4567-e89b-12d3-a456-426655440000'],
['key' => 'role', 'relation' => '=', 'value' => 'admin'],
]),
])
->andReturn($response);

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

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

/** @test */
public function it_sends_nothing_and_returns_null_when_player_id_empty()
{
Expand Down
20 changes: 20 additions & 0 deletions tests/NotifiableMultipleTags.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace NotificationChannels\OneSignal\Test;

class NotifiableMultipleTags
{
use \Illuminate\Notifications\Notifiable;

/**
* @return array
*/
public function routeNotificationForOneSignal()
{
return ['tags' => [
['key' => 'device_uuid', 'relation' => '=', 'value' => '123e4567-e89b-12d3-a456-426655440000'],
['key' => 'role', 'relation' => '=', 'value' => 'admin'],
],
];
}
}