Skip to content

Commit

Permalink
Revert "Swap Vonage Client to SMS instead of legacy message (#65)" (#71)
Browse files Browse the repository at this point in the history
This reverts commit 55c703f.
  • Loading branch information
driesvints authored Jan 26, 2023
1 parent 81122ec commit 0ad09ae
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 82 deletions.
19 changes: 9 additions & 10 deletions src/Channels/VonageSmsChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Illuminate\Notifications\Messages\VonageMessage;
use Illuminate\Notifications\Notification;
use Vonage\Client as VonageClient;
use Vonage\SMS\Message\SMS;

class VonageSmsChannel
{
Expand Down Expand Up @@ -55,18 +54,18 @@ public function send($notifiable, Notification $notification)
$message = new VonageMessage($message);
}

$vonageSms = new SMS(
$to,
$message->from ?: $this->from,
trim($message->content)
);

$vonageSms->setClientRef($message->clientReference);
$payload = [
'type' => $message->type,
'from' => $message->from ?: $this->from,
'to' => $to,
'text' => trim($message->content),
'client-ref' => $message->clientReference,
];

if ($message->statusCallback) {
$vonageSms->setDeliveryReceiptCallback($message->statusCallback);
$payload['callback'] = $message->statusCallback;
}

return ($message->client ?? $this->client)->sms()->send($vonageSms);
return ($message->client ?? $this->client)->message()->send($payload);
}
}
135 changes: 63 additions & 72 deletions tests/Unit/Channels/VonageSmsChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Illuminate\Notifications\Tests\Unit\Channels;

use Hamcrest\Core\IsEqual;
use Illuminate\Notifications\Channels\VonageSmsChannel;
use Illuminate\Notifications\Messages\VonageMessage;
use Illuminate\Notifications\Notifiable;
Expand All @@ -11,7 +10,6 @@
use Mockery as m;
use PHPUnit\Framework\TestCase;
use Vonage\Client;
use Vonage\SMS\Message\SMS;

class VonageSmsChannelTest extends TestCase
{
Expand All @@ -26,14 +24,14 @@ public function testSmsIsSentViaVonage()
$vonage = m::mock(Client::class), '4444444444'
);

$mockSms = (new SMS(
'5555555555',
'4444444444',
'this is my message'
));

$vonage->shouldReceive('sms->send')
->with(IsEqual::equalTo($mockSms))
$vonage->shouldReceive('message->send')
->with([
'type' => 'text',
'from' => '4444444444',
'to' => '5555555555',
'text' => 'this is my message',
'client-ref' => '',
])
->once();

$channel->send($notifiable, $notification);
Expand All @@ -42,12 +40,14 @@ public function testSmsIsSentViaVonage()
public function testSmsIsSentViaVonageWithCustomClient()
{
$customVonage = m::mock(Client::class);
$customVonage->shouldReceive('sms->send')
->with(IsEqual::equalTo(new SMS(
'5555555555',
'4444444444',
'this is my message'
)))
$customVonage->shouldReceive('message->send')
->with([
'type' => 'text',
'from' => '4444444444',
'to' => '5555555555',
'text' => 'this is my message',
'client-ref' => '',
])
->once();

$notification = new NotificationVonageSmsChannelTestCustomClientNotification($customVonage);
Expand All @@ -57,7 +57,7 @@ public function testSmsIsSentViaVonageWithCustomClient()
$vonage = m::mock(Client::class), '4444444444'
);

$vonage->shouldNotReceive('sms->send');
$vonage->shouldNotReceive('message->send');

$channel->send($notifiable, $notification);
}
Expand All @@ -71,14 +71,14 @@ public function testSmsIsSentViaVonageWithCustomFrom()
$vonage = m::mock(Client::class), '4444444444'
);

$mockSms = (new SMS(
'5555555555',
'5554443333',
'this is my message'
));

$vonage->shouldReceive('sms->send')
->with(IsEqual::equalTo($mockSms))
$vonage->shouldReceive('message->send')
->with([
'type' => 'unicode',
'from' => '5554443333',
'to' => '5555555555',
'text' => 'this is my message',
'client-ref' => '',
])
->once();

$channel->send($notifiable, $notification);
Expand All @@ -87,16 +87,14 @@ public function testSmsIsSentViaVonageWithCustomFrom()
public function testSmsIsSentViaVonageWithCustomFromAndClient()
{
$customVonage = m::mock(Client::class);

$mockSms = new SMS(
'5555555555',
'5554443333',
'this is my message',
'unicode'
);

$customVonage->shouldReceive('sms->send')
->with(IsEqual::equalTo($mockSms))
$customVonage->shouldReceive('message->send')
->with([
'type' => 'unicode',
'from' => '5554443333',
'to' => '5555555555',
'text' => 'this is my message',
'client-ref' => '',
])
->once();

$notification = new NotificationVonageSmsChannelTestCustomFromAndClientNotification($customVonage);
Expand All @@ -106,7 +104,7 @@ public function testSmsIsSentViaVonageWithCustomFromAndClient()
$vonage = m::mock(Client::class), '4444444444'
);

$vonage->shouldNotReceive('sms->send');
$vonage->shouldNotReceive('message->send');

$channel->send($notifiable, $notification);
}
Expand All @@ -120,17 +118,14 @@ public function testSmsIsSentViaVonageWithCustomFromAndClientRef()
$vonage = m::mock(Client::class), '4444444444'
);

$mockSms = new SMS(
'5555555555',
'5554443333',
'this is my message',
'unicode'
);

$mockSms->setClientRef('11');

$vonage->shouldReceive('sms->send')
->with(IsEqual::equalTo($mockSms))
$vonage->shouldReceive('message->send')
->with([
'type' => 'unicode',
'from' => '5554443333',
'to' => '5555555555',
'text' => 'this is my message',
'client-ref' => '11',
])
->once();

$channel->send($notifiable, $notification);
Expand All @@ -139,18 +134,14 @@ public function testSmsIsSentViaVonageWithCustomFromAndClientRef()
public function testSmsIsSentViaVonageWithCustomClientFromAndClientRef()
{
$customVonage = m::mock(Client::class);

$mockSms = new SMS(
'5555555555',
'5554443333',
'this is my message',
'unicode'
);

$mockSms->setClientRef('11');

$customVonage->shouldReceive('sms->send')
->with(IsEqual::equalTo($mockSms))
$customVonage->shouldReceive('message->send')
->with([
'type' => 'unicode',
'from' => '5554443333',
'to' => '5555555555',
'text' => 'this is my message',
'client-ref' => '11',
])
->once();

$notification = new NotificationVonageSmsChannelTestCustomClientFromAndClientRefNotification($customVonage);
Expand All @@ -160,7 +151,7 @@ public function testSmsIsSentViaVonageWithCustomClientFromAndClientRef()
$vonage = m::mock(Client::class), '4444444444'
);

$vonage->shouldNotReceive('sms->send');
$vonage->shouldNotReceive('message->send');

$channel->send($notifiable, $notification);
}
Expand All @@ -174,17 +165,16 @@ public function testCallbackIsApplied()
$vonage = m::mock(Client::class), '4444444444'
);

$mockSms = (new SMS(
'5555555555',
'4444444444',
'this is my message'
));

$mockSms->setDeliveryReceiptCallback('https://example.com');

$vonage->shouldReceive('sms->send')
->with(IsEqual::equalTo($mockSms))
->once();
$vonage->shouldReceive('message->send')
->with([
'type' => 'text',
'from' => '4444444444',
'to' => '5555555555',
'text' => 'this is my message',
'client-ref' => '',
'callback' => 'https://example.com',
])
->once();

$channel->send($notifiable, $notification);
}
Expand Down Expand Up @@ -279,6 +269,7 @@ class NotificationVonageSmsChannelTestCallback extends Notification
{
public function toVonage($notifiable)
{
return (new VonageMessage('this is my message'))->statusCallback('https://example.com');
return (new VonageMessage('this is my message'))
->statusCallback('https://example.com');
}
}

0 comments on commit 0ad09ae

Please sign in to comment.