diff --git a/src/OneSignalChannel.php b/src/OneSignalChannel.php index b1c3ace..d0d040c 100644 --- a/src/OneSignalChannel.php +++ b/src/OneSignalChannel.php @@ -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()], diff --git a/src/OneSignalMessage.php b/src/OneSignalMessage.php index 3fb8fcb..6278390 100644 --- a/src/OneSignalMessage.php +++ b/src/OneSignalMessage.php @@ -14,6 +14,8 @@ class OneSignalMessage private ?string $icon = null; + private ?string $webUrl = null; + public static function create($body = ''): self { return new static($body); @@ -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; @@ -114,4 +123,9 @@ public function getIcon(): ?string { return $this->icon; } + + public function getWebUrl(): ?string + { + return $this->webUrl; + } } diff --git a/tests/ChannelTest.php b/tests/ChannelTest.php index 228e157..30c5871 100644 --- a/tests/ChannelTest.php +++ b/tests/ChannelTest.php @@ -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 { @@ -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; + }); + } }