diff --git a/src/LobChannel.php b/src/LobChannel.php index f26dda7..d5cd164 100644 --- a/src/LobChannel.php +++ b/src/LobChannel.php @@ -34,10 +34,11 @@ public function send($notifiable, Notification $notification) $messageContent = $message->toArray(); - if ($address = $notifiable->routeNotificationFor('Lob') && ! isset($messageContent['to'])) { + if (($address = $notifiable->routeNotificationFor('Lob')) && ! isset($messageContent['to'])) { $messageContent['to'] = $address; } + $this->lob->{$message->type}()->create($messageContent); } } diff --git a/tests/ChannelTest.php b/tests/ChannelTest.php index d286c4d..a3fb3a1 100644 --- a/tests/ChannelTest.php +++ b/tests/ChannelTest.php @@ -42,15 +42,35 @@ public function it_can_send_a_notification() $this->channel->send($this->notifiable, $this->notification); } + + /** @test */ + public function it_can_send_a_notification_with_default_to_address() + { + $notification = new TestNotificationWithToAddress; + + $message = $notification->toLobPostcard($this->notifiable); + + $data = $message->toArray(); + + $this->lobClient->shouldReceive('postcards')->andReturn($postcard = Mockery::mock(Postcards::class)); + + $expectedData = $data; + + $expectedData['to'] = 'address_default_id'; + + $postcard->shouldReceive('create')->with($expectedData); + + $this->channel->send($this->notifiable, $notification); + } } class TestNotifiable { use Notifiable; - public function routeNotificationForPusherPushNotifications() + public function routeNotificationForLob() { - return 'interest_name'; + return 'address_default_id'; } } @@ -64,3 +84,13 @@ public function toLobPostcard($notifiable) ->message('test'); } } + +class TestNotificationWithToAddress extends Notification +{ + public function toLobPostcard($notifiable) + { + return LobPostcard::create() + ->front('http://image.site/image.png') + ->message('test'); + } +}