-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove string type cast for payload values. Add setSandboxMode method. (
#8) * add setSandboxMode method * remove type casting to allow addDynamicTemplateData to accept arrays. (#7) * update test cases * add test case * refactor * update readme and changelog Co-authored-by: Tim Gieseking <[email protected]>
- Loading branch information
Showing
5 changed files
with
87 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,51 +63,4 @@ public function toSendGrid($notifiable) | |
|
||
$channel->send($notifiable, $notification); | ||
} | ||
|
||
public function testEmailIsNotSentViaSendGridWithSandbox() | ||
{ | ||
$notification = new class extends Notification { | ||
public function toSendGrid($notifiable) | ||
{ | ||
return (new SendGridMessage('sendgrid-template-id')) | ||
->from('[email protected]', 'Example User') | ||
->to('[email protected]', 'Example User1') | ||
->replyTo('[email protected]', 'Reply To') | ||
->payload([ | ||
'bar' => 'foo', | ||
'baz' => 'foo2', | ||
]) | ||
->enableSandboxMode(); | ||
} | ||
}; | ||
|
||
$notifiable = new class { | ||
use Notifiable; | ||
}; | ||
|
||
$channel = new SendGridChannel( | ||
$sendgrid = Mockery::mock(new SendGrid('x')) | ||
); | ||
|
||
$response = Mockery::mock(Response::class); | ||
$response->shouldReceive('statusCode')->andReturn(200); | ||
|
||
$message = $notification->toSendGrid($notifiable); | ||
|
||
$this->assertEquals($message->templateId, 'sendgrid-template-id'); | ||
$this->assertEquals($message->from->getEmail(), '[email protected]'); | ||
$this->assertEquals($message->from->getName(), 'Example User'); | ||
$this->assertEquals($message->tos[0]->getEmail(), '[email protected]'); | ||
$this->assertEquals($message->tos[0]->getName(), 'Example User1'); | ||
$this->assertEquals($message->payload['bar'], 'foo'); | ||
$this->assertEquals($message->payload['baz'], 'foo2'); | ||
$this->assertEquals($message->replyTo->getEmail(), '[email protected]'); | ||
$this->assertEquals($message->replyTo->getName(), 'Reply To'); | ||
$this->assertEquals($message->sandboxMode, true); | ||
|
||
// TODO: Verify that the Mail instance passed contains all the info from above | ||
$sendgrid->shouldReceive('send')->once()->andReturn($response); | ||
|
||
$channel->send($notifiable, $notification); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace NotificationChannels\SendGrid\Test; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use NotificationChannels\SendGrid\SendGridMessage; | ||
|
||
class SendGridMessageTest extends TestCase | ||
{ | ||
public function testDynamicVariables() | ||
{ | ||
$message = new SendGridMessage('template-id'); | ||
$message->payload($payload = [ | ||
'bar' => 'string', | ||
'baz' => null, | ||
'foo' => [ | ||
'nested' => 'array', | ||
'number' => 1235, | ||
'array' => [1, 2, 3], | ||
], | ||
]); | ||
|
||
$mail = $message->build(); | ||
$this->assertEquals( | ||
$payload, | ||
$mail->getPersonalization()->getDynamicTemplateData() | ||
); | ||
} | ||
|
||
public function testSandboxMode() | ||
{ | ||
$message = new SendGridMessage('template-id'); | ||
$this->assertFalse($message->sandboxMode, 'Sandbox mode is turned off by default'); | ||
$this->assertFalse( | ||
$message->build()->getMailSettings()->getSandboxMode()->getEnable(), | ||
'Sandbox mode is disabled in Sendgrid mail settings' | ||
); | ||
|
||
$message->enableSandboxMode(); | ||
$this->assertTrue($message->sandboxMode, 'Sandbox mode can be enabled'); | ||
$this->assertTrue( | ||
$message->build()->getMailSettings()->getSandboxMode()->getEnable(), | ||
'Sandbox mode is enabled in Sendgrid mail settings' | ||
); | ||
|
||
$message->setSandboxMode(false); | ||
$this->assertFalse($message->sandboxMode, 'Sandbox mode can be turned off'); | ||
$this->assertFalse( | ||
$message->build()->getMailSettings()->getSandboxMode()->getEnable(), | ||
'Sandbox mode is disabled in Sendgrid mail settings' | ||
); | ||
} | ||
} |