From 2db0619d8a3fcd0e6c97019e89f1e67a6494a3a9 Mon Sep 17 00:00:00 2001 From: Nathan Perkins Date: Tue, 27 Aug 2019 22:59:58 -0600 Subject: [PATCH] Revise domain creation assertions and add tests Based on feedback from @DavidGarciaCat. --- src/Api/Domain.php | 3 +-- tests/Api/DomainTest.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/Api/Domain.php b/src/Api/Domain.php index 0b14684b..e05a2519 100644 --- a/src/Api/Domain.php +++ b/src/Api/Domain.php @@ -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); diff --git a/tests/Api/DomainTest.php b/tests/Api/DomainTest.php index cbe23edf..86ab5e7b 100644 --- a/tests/Api/DomainTest.php +++ b/tests/Api/DomainTest.php @@ -85,6 +85,35 @@ 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'); @@ -92,6 +121,7 @@ public function testCreateWithPassword() 'name' => 'example.com', 'smtp_password' => 'foo', 'spam_action' => 'bar', + 'wildcard' => 'true', ]); $this->setHydrateClass(CreateResponse::class);