Skip to content

Commit

Permalink
Merge pull request #9 from zanderwar/tests/coverage
Browse files Browse the repository at this point in the history
Test coverage improvements
  • Loading branch information
zanderwar authored Feb 2, 2018
2 parents 78325a6 + e4cc2f9 commit c24d451
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 15 deletions.
37 changes: 22 additions & 15 deletions src/SendGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class SendGrid
* @var string
*/
protected $replyTo;

/**
* @var string
*/
Expand All @@ -77,13 +78,19 @@ class SendGrid
*/
protected $attachments;

/** @var int */
/**
* @var int
*/
protected $sendAt;

/** @var bool */
/**
* @var bool
*/
protected $sandbox = false;

/** @var ArrayList */
/**
* @var ArrayList
*/
protected $customArgs;

/**
Expand Down Expand Up @@ -533,18 +540,18 @@ public function getApiKey()
public function getErrorMap()
{
$map = [
['Code' => 200, 'Message' => 'OK', 'Reason' => 'Your message is valid, but it is not queued to be delivered.'],
['Code' => 202, 'Message' => 'ACCEPTED', 'Reason' => 'Your message is both valid, and queued to be delivered.'],
['Code' => 400, 'Message' => 'BAD REQUEST', 'Reason' => ''],
['Code' => 401, 'Message' => 'UNAUTHORIZED', 'Reason' => 'You do not have authorization to make the request.'],
['Code' => 403, 'Message' => 'FORBIDDEN', 'Reason' => ''],
['Code' => 404, 'Message' => 'NOT FOUND', 'Reason' => 'The resource you tried to locate could not be found or does not exist.'],
['Code' => 405, 'Message' => 'METHOD NOT ALLOWED', 'Reason' => ''],
['Code' => 413, 'Message' => 'PAYLOAD TOO LARGE', 'Reason' => 'The JSON payload you have included in your request is too large.'],
['Code' => 415, 'Message' => 'UNSUPPORTED MEDIA TYPE', 'Reason' => ''],
['Code' => 429, 'Message' => 'TOO MANY REQUESTS', 'Reason' => 'The number of requests you have made exceeds SendGrid’s rate limitations'],
['Code' => 500, 'Message' => 'SERVER UNAVAILABLE', 'Reason' => 'An error occurred on a SendGrid server.'],
['Code' => 503, 'Message' => 'SERVICE NOT AVAILABLE', 'Reason' => 'The SendGrid v3 Web API is not available.']
ArrayData::create(['Code' => 200, 'Message' => 'OK', 'Reason' => 'Your message is valid, but it is not queued to be delivered.']),
ArrayData::create(['Code' => 202, 'Message' => 'ACCEPTED', 'Reason' => 'Your message is both valid, and queued to be delivered.']),
ArrayData::create(['Code' => 400, 'Message' => 'BAD REQUEST', 'Reason' => '']),
ArrayData::create(['Code' => 401, 'Message' => 'UNAUTHORIZED', 'Reason' => 'You do not have authorization to make the request.']),
ArrayData::create(['Code' => 403, 'Message' => 'FORBIDDEN', 'Reason' => '']),
ArrayData::create(['Code' => 404, 'Message' => 'NOT FOUND', 'Reason' => 'The resource you tried to locate could not be found or does not exist.']),
ArrayData::create(['Code' => 405, 'Message' => 'METHOD NOT ALLOWED', 'Reason' => '']),
ArrayData::create(['Code' => 413, 'Message' => 'PAYLOAD TOO LARGE', 'Reason' => 'The JSON payload you have included in your request is too large.']),
ArrayData::create(['Code' => 415, 'Message' => 'UNSUPPORTED MEDIA TYPE', 'Reason' => '']),
ArrayData::create(['Code' => 429, 'Message' => 'TOO MANY REQUESTS', 'Reason' => 'The number of requests you have made exceeds SendGrid’s rate limitations']),
ArrayData::create(['Code' => 500, 'Message' => 'SERVER UNAVAILABLE', 'Reason' => 'An error occurred on a SendGrid server.']),
ArrayData::create(['Code' => 503, 'Message' => 'SERVICE NOT AVAILABLE', 'Reason' => 'The SendGrid v3 Web API is not available.']),
];

return ArrayList::create($map);
Expand Down
90 changes: 90 additions & 0 deletions tests/SendGridTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Vulcan\SendGrid\Tests;

use SilverStripe\Dev\FunctionalTest;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\View\ArrayData;
Expand Down Expand Up @@ -157,4 +158,93 @@ public function testCustomArgs()
$this->assertTrue(true);
}
}

/**
* @covers \Vulcan\SendGrid\SendGrid::getErrorMap()
*/
public function testErrorMap()
{
$this->assertInstanceOf(ArrayList::class, $this->sendGrid->getErrorMap());
}

/**
* @covers \Vulcan\SendGrid\SendGrid::getErrorDefinition()
*/
public function testErrorDefinition()
{
$definition = $this->sendGrid->getErrorDefinition(200);

$this->assertEquals('OK', $definition->Message);
}

/**
* @covers \Vulcan\SendGrid\SendGrid::isSandbox()
* @covers \Vulcan\SendGrid\SendGrid::setSandboxMode()
*/
public function testSandboxMode()
{
$this->sendGrid->setSandboxMode(true);
$this->assertTrue($this->sendGrid->isSandbox());
}

/**
* @covers \Vulcan\SendGrid\SendGrid::setTemplateId()
* @covers \Vulcan\SendGrid\SendGrid::getTemplateId()
*/
public function testTemplateId()
{
$id = '1234-5678-9123-4567';
$this->sendGrid->setTemplateId($id);
$this->assertEquals($id, $this->sendGrid->getTemplateId());
}

/**
* @covers \Vulcan\SendGrid\SendGrid::getApiKey()
*/
public function testGetApiKey()
{
if ($this->hasApiKey) {
$this->assertEquals(getenv('SG_API_KEY'), $this->sendGrid->getApiKey());
return;
}

$this->assertEquals('XXXX-XXXX-XXXX-XXXX', $this->sendGrid->getApiKey());
}

/**
* @covers \Vulcan\SendGrid\SendGrid::setReplyTo()
* @covers \Vulcan\SendGrid\SendGrid::getReplyTo()
*/
public function testReplyTo()
{
$this->sendGrid->setReplyTo('[email protected]');
$this->assertEquals('[email protected]', $this->sendGrid->getReplyTo());
}

/**
* @covers \Vulcan\SendGrid\SendGrid::setFrom()
* @covers \Vulcan\SendGrid\SendGrid::setFromName()
* @covers \Vulcan\SendGrid\SendGrid::getFrom()
* @covers \Vulcan\SendGrid\SendGrid::getFromName()
*/
public function testFrom()
{
$this->sendGrid->setFrom('[email protected]');
$this->sendGrid->setFromName('Jane Doe');

$this->assertEquals('[email protected]', $this->sendGrid->getFrom());
$this->assertEquals('Jane Doe', $this->sendGrid->getFromName());
}

/**
* @covers \Vulcan\SendGrid\SendGrid::setSubject()
* @covers \Vulcan\SendGrid\SendGrid::getSubject()
*/
public function testSubject()
{
$subject = 'Where have you been John!';
$this->sendGrid->setSubject($subject);

$this->assertEquals($subject, $this->sendGrid->getSubject());
}
}

0 comments on commit c24d451

Please sign in to comment.