Revise domain creation assertions and add tests

Based on feedback from @DavidGarciaCat.
This commit is contained in:
Nathan Perkins 2019-08-27 22:59:58 -06:00 committed by David Garcia
parent c9bbf8e45f
commit 2db0619d8a
2 changed files with 31 additions and 2 deletions

View File

@ -90,12 +90,11 @@ class Domain extends HttpApi
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);

View File

@ -85,6 +85,20 @@ JSON
}
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');
@ -95,6 +109,22 @@ JSON
]);
$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);
$api = $this->getApiInstance();
$api->create('example.com', 'foo', 'bar', true);
}