Skip to content

Commit

Permalink
Added Tests for GeoReference, Secondary, and Secondary Count Enpoint.…
Browse files Browse the repository at this point in the history
… Fixed minor issue with Secondary Count
  • Loading branch information
Eric Devenport authored and Eric Devenport committed Sep 9, 2024
1 parent f9c5f6b commit 52e2721
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/US_Enrichment/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
30 changes: 30 additions & 0 deletions tests/US_Enrichment/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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());
}
}
103 changes: 102 additions & 1 deletion tests/US_Enrichment/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
class ResponseTest extends TestCase
{
private $financialObj,
$principalObj;
$principalObj,
$geoReferenceObj,
$secondaryObj,
$secondaryCountObj;

public function setUp() : void
{
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 52e2721

Please sign in to comment.