From 52e272199ed5ac0ff0cce931d60fd023fa94e943 Mon Sep 17 00:00:00 2001 From: Eric Devenport Date: Mon, 9 Sep 2024 13:40:29 -0600 Subject: [PATCH] Added Tests for GeoReference, Secondary, and Secondary Count Enpoint. Fixed minor issue with Secondary Count --- src/US_Enrichment/Result.php | 12 ++-- tests/US_Enrichment/ClientTest.php | 30 ++++++++ tests/US_Enrichment/ResponseTest.php | 103 ++++++++++++++++++++++++++- 3 files changed, 139 insertions(+), 6 deletions(-) diff --git a/src/US_Enrichment/Result.php b/src/US_Enrichment/Result.php index 6e41ce6..9006feb 100644 --- a/src/US_Enrichment/Result.php +++ b/src/US_Enrichment/Result.php @@ -64,13 +64,15 @@ private function createAttributes($dataSetName, $dataSubsetName, $attributesObj) } private function createSecondaryData($responseObj, $dataSubsetName) { - if ($dataSubsetName = 'count'){ + if ($dataSubsetName == 'count'){ $attributes = new SecondaryCountAttributes($responseObj); $this->count = $attributes->count; } - $attributes = new SecondaryAttributes($responseObj); - $this->rootAddress = $attributes->rootAddress; - $this->aliases[] = $attributes->aliases; - $this->secondaries[] = $attributes->secondaries; + else { + $attributes = new SecondaryAttributes($responseObj); + $this->rootAddress = $attributes->rootAddress; + $this->aliases[] = $attributes->aliases; + $this->secondaries[] = $attributes->secondaries; + } } } \ No newline at end of file diff --git a/tests/US_Enrichment/ClientTest.php b/tests/US_Enrichment/ClientTest.php index d03ce29..e8dcd19 100644 --- a/tests/US_Enrichment/ClientTest.php +++ b/tests/US_Enrichment/ClientTest.php @@ -9,11 +9,13 @@ require_once(dirname(dirname(__FILE__)) . '/Mocks/MockSender.php'); require_once(dirname(dirname(__FILE__)) . '/Mocks/MockCrashingSender.php'); require_once(dirname(dirname(dirname(__FILE__))) . '/src/US_Enrichment/Client.php'); +require_once(dirname(dirname(dirname(__FILE__))) . '/src/US_Enrichment/Lookup.php'); require_once(dirname(dirname(dirname(__FILE__))) . '/src/URLPrefixSender.php'); use SmartyStreets\PhpSdk\Tests\Mocks\MockSerializer; use SmartyStreets\PhpSdk\Tests\Mocks\RequestCapturingSender; use SmartyStreets\PhpSdk\URLPrefixSender; use SmartyStreets\PhpSdk\US_Enrichment\Client; +use SmartyStreets\PhpSdk\US_Enrichment\Lookup; use PHPUnit\Framework\TestCase; class ClientTest extends TestCase { @@ -28,4 +30,32 @@ public function testSendingLookup() { $this->assertEquals("http://localhost/123/property/principal?", $capturingSender->getRequest()->getUrl()); } + public function testSendingAddressComponentLookup() { + $capturingSender = new RequestCapturingSender(); + $sender = new URLPrefixSender("http://localhost/", $capturingSender); + $serializer = new MockSerializer(null); + $client = new Client($sender, $serializer); + $lookup = new Lookup(); + $lookup->setStreet("123 Test Street"); + $lookup->setCity("Test City"); + $lookup->setState("Test State"); + $lookup->setZipcode("Test Zipcode"); + + $client->sendPropertyPrincipalLookup($lookup); + + $this->assertEquals("http://localhost/search/property/principal?street=123+Test+Street&city=Test+City&state=Test+State&zipcode=Test+Zipcode", $capturingSender->getRequest()->getUrl()); + } + + public function testSendingFreeformLookup() { + $capturingSender = new RequestCapturingSender(); + $sender = new URLPrefixSender("http://localhost/", $capturingSender); + $serializer = new MockSerializer(null); + $client = new Client($sender, $serializer); + $lookup = new Lookup(); + $lookup->setFreeform("123 Test Street City State Zipcode"); + + $client->sendPropertyPrincipalLookup($lookup); + + $this->assertEquals("http://localhost/search/property/principal?freeform=123+Test+Street+City+State+Zipcode", $capturingSender->getRequest()->getUrl()); + } } diff --git a/tests/US_Enrichment/ResponseTest.php b/tests/US_Enrichment/ResponseTest.php index f2d074a..b7e385d 100644 --- a/tests/US_Enrichment/ResponseTest.php +++ b/tests/US_Enrichment/ResponseTest.php @@ -10,7 +10,10 @@ class ResponseTest extends TestCase { private $financialObj, - $principalObj; + $principalObj, + $geoReferenceObj, + $secondaryObj, + $secondaryCountObj; public function setUp() : void { @@ -40,6 +43,53 @@ public function setUp() : void 'assessor_taxroll_update' => 'test_update' ), ); + + $this->geoReferenceObj = array( + 'smarty_key' => '123', + 'data_set_name' => 'geo-reference', + 'data_subset_name' => null, + 'attributes' => array( + 'census_block' => array( + 'accuracy' => 'test_accuracy', + 'geoid' => 'test_id', + ) + ), + ); + + $this->secondaryObj = array( + 'smarty_key' => '123', + 'root_address' => array( + 'secondary_count' => 2, + 'smarty_key' => '123', + ), + 'aliases' => array( + array( + 'smarty_key' => '123', + 'primary_number' => '1234', + ), + array( + 'smarty_key' => '123', + 'primary_number' => '2345', + ) + ), + 'secondaries' => array( + array( + 'smarty_key' => '234', + 'secondary_designator' => 'apt', + ), + array( + 'smarty_key' => '345', + 'secondary_designator' => 'apt', + ) + ), + ); + + $this->secondaryCountObj = array( + 'smarty_key' => '123', + 'count' => 2, + ); + + } public function testAllFinancialFieldsFilledCorrectly() @@ -74,4 +124,55 @@ public function testAllPrincipalFieldsFilledCorrectly() $this->assertEquals('2', $attributes->bedrooms); $this->assertEquals('test_update', $attributes->assessorTaxrollUpdate); } + + public function testAllGeoReferenceFieldsFilledCorrectly() + { + $result = new Result($this->geoReferenceObj); + + $this->assertEquals('123', $result->smartyKey); + $this->assertEquals('geo-reference', $result->dataSetName); + $this->assertNull($result->dataSubsetName); + + $attributes = $result->attributes; + $censusBlock = $attributes->censusBlock; + + $this->assertEquals('test_accuracy', $censusBlock->accuracy); + $this->assertEquals('test_id', $censusBlock->geoid); + } + + public function testAllSecondaryFieldsFilledCorrectly() + { + $result = new Result($this->secondaryObj); + + $this->assertEquals('123', $result->smartyKey); + + $rootAddress = $result->rootAddress; + + $this->assertEquals(2, $rootAddress->secondaryCount); + $this->assertEquals('123', $rootAddress->smartyKey); + + $aliases = $result->aliases; + + $this->assertEquals('123', $aliases[0][0]->smartyKey); + $this->assertEquals('1234', $aliases[0][0]->primaryNumber); + + $this->assertEquals('123', $aliases[0][1]->smartyKey); + $this->assertEquals('2345', $aliases[0][1]->primaryNumber); + + $secondaries = $result->secondaries; + + $this->assertEquals('234', $secondaries[0][0]->smartyKey); + $this->assertEquals('apt', $secondaries[0][0]->secondaryDesignator); + + $this->assertEquals('345', $secondaries[0][1]->smartyKey); + $this->assertEquals('apt', $secondaries[0][1]->secondaryDesignator); + } + + public function testAllSecondaryCountFieldsFilledCorrectly() + { + $result = new Result($this->secondaryCountObj); + + $this->assertEquals('123', $result->smartyKey); + $this->assertEquals(2, $result->count); + } }