Skip to content

Commit

Permalink
Revise domain creation assertions and add tests
Browse files Browse the repository at this point in the history
Based on feedback from @DavidGarciaCat.
  • Loading branch information
nathanntg authored and DavidGarciaCat committed Aug 29, 2019
1 parent c9bbf8e commit 2db0619
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/Api/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,11 @@ public function create(string $domain, string $smtpPass = null, string $spamActi

if (!empty($smtpPass)) {
Assert::stringNotEmpty($smtpPass);
Assert::lengthBetween($smtpPass, 5, 32, 'SMTP password must be between 5 and 32 characters.');

$params['smtp_password'] = $smtpPass;
}

if (null !== $spamAction) {
if (!empty($spamAction)) {
// TODO(sean.johnson): Extended spam filter input validation.
Assert::stringNotEmpty($spamAction);

Expand Down
30 changes: 30 additions & 0 deletions tests/Api/DomainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,43 @@ public function testCreate()
}

public function testCreateWithPassword()
{
$this->setRequestMethod('POST');
$this->setRequestUri('/v3/domains');
$this->setRequestBody([
'name' => 'example.com',
'smtp_password' => 'foo',
]);
$this->setHydrateClass(CreateResponse::class);

$api = $this->getApiInstance();
$api->create('example.com', 'foo');
}

public function testCreateWithPasswordSpamAction()
{
$this->setRequestMethod('POST');
$this->setRequestUri('/v3/domains');
$this->setRequestBody([
'name' => 'example.com',
'smtp_password' => 'foo',
'spam_action' => 'bar',
]);
$this->setHydrateClass(CreateResponse::class);

$api = $this->getApiInstance();
$api->create('example.com', 'foo', 'bar');
}

public function testCreateWithPasswordSpamActionWildcard()
{
$this->setRequestMethod('POST');
$this->setRequestUri('/v3/domains');
$this->setRequestBody([
'name' => 'example.com',
'smtp_password' => 'foo',
'spam_action' => 'bar',
'wildcard' => 'true',
]);
$this->setHydrateClass(CreateResponse::class);

Expand Down

0 comments on commit 2db0619

Please sign in to comment.