Skip to content

Commit

Permalink
add test for default to address
Browse files Browse the repository at this point in the history
  • Loading branch information
themsaid committed Aug 14, 2016
1 parent 943e70f commit 6dbd1a1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/LobChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
34 changes: 32 additions & 2 deletions tests/ChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}

Expand All @@ -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');
}
}

0 comments on commit 6dbd1a1

Please sign in to comment.