Skip to content

Commit

Permalink
Add web url property (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
epicentre authored Sep 18, 2023
1 parent ba9fe10 commit c462b64
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/OneSignalChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function send($notifiable, Notification $notification): ?object
'headings' => $message->getHeadings(),
'contents' => $message->getBody(),
'data' => $message->getData(),
'web_url' => $message->getWebUrl(),
'large_icon' => $message->getIcon(),
'huawei_large_icon' => $message->getIcon(),
'ios_attachments' => ['icon' => $message->getIcon()],
Expand Down
14 changes: 14 additions & 0 deletions src/OneSignalMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class OneSignalMessage

private ?string $icon = null;

private ?string $webUrl = null;

public static function create($body = ''): self
{
return new static($body);
Expand Down Expand Up @@ -90,6 +92,13 @@ public function setIcon(string $icon): self
return $this;
}

public function setWebUrl(?string $webUrl = null): self
{
$this->webUrl = $webUrl;

return $this;
}

public function getAppId(): ?string
{
return $this->appId;
Expand All @@ -114,4 +123,9 @@ public function getIcon(): ?string
{
return $this->icon;
}

public function getWebUrl(): ?string
{
return $this->webUrl;
}
}
26 changes: 26 additions & 0 deletions tests/ChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
use Illuminate\Support\Facades\Http;
use Macellan\OneSignal\Exceptions\CouldNotSendNotification;
use Macellan\OneSignal\OneSignalChannel;
use Macellan\OneSignal\OneSignalMessage;
use Macellan\OneSignal\Tests\Notifications\TestIconNotification;
use Macellan\OneSignal\Tests\Notifications\TestNotification;
use Macellan\OneSignal\Tests\Notifications\TestOtherAppIdNotification;
use Mockery\MockInterface;

class ChannelTest extends TestCase
{
Expand Down Expand Up @@ -101,4 +103,28 @@ public function test_icon()
$request['ios_attachments'] == ['icon' => 'test-icon.jpg'];
});
}

public function test_web_url(): void
{
Http::fake([
'api/v1/notifications' => Http::response([
'id' => '931082f5-e442-42b1-a951-19e7e45dee39',
'recipients' => 1,
'external_id' => null,
]),
]);

$webUrl = 'https://macellan.net/';
$notification = $this->partialMock(TestNotification::class, function (MockInterface $mock) use ($webUrl): void {
$mock->makePartial()
->shouldReceive('toOneSignal')
->andReturn((new OneSignalMessage())->setWebUrl($webUrl));
});

(new Notifiable)->notify($notification);

Http::assertSent(function (Request $request) use ($webUrl) {
return $request['web_url'] == $webUrl;
});
}
}

0 comments on commit c462b64

Please sign in to comment.