Fix property assessor geocode fallback
This commit is contained in:
@@ -224,3 +224,45 @@ test("assessProperty renders a PDF when recipient email is present", async () =>
|
||||
const stat = await fs.promises.stat(outputPath);
|
||||
assert.ok(stat.size > 1000);
|
||||
});
|
||||
|
||||
test("assessProperty prioritizes student housing guidance over investment fallback keywords", async () => {
|
||||
const result = await assessProperty(
|
||||
{
|
||||
address: "1011 Ennis Joslin Rd APT 235, Corpus Christi, TX 78412",
|
||||
assessmentPurpose:
|
||||
"college housing for daughter attending TAMU-CC; prioritize proximity, safety/livability, and resale/rental fallback"
|
||||
},
|
||||
{
|
||||
resolvePublicRecordsFn: async () => samplePublicRecords,
|
||||
discoverListingSourcesFn: async () => ({
|
||||
attempts: ["Zillow discovery located a property page from the address."],
|
||||
zillowUrl:
|
||||
"https://www.zillow.com/homedetails/1011-Ennis-Joslin-Rd-APT-235-Corpus-Christi-TX-78412/28848927_zpid/",
|
||||
harUrl: null
|
||||
}),
|
||||
extractPhotoDataFn: async (source, url) => ({
|
||||
source,
|
||||
requestedUrl: url,
|
||||
finalUrl: url,
|
||||
expectedPhotoCount: 20,
|
||||
complete: true,
|
||||
photoCount: 20,
|
||||
imageUrls: ["https://photos.example/1.jpg"],
|
||||
notes: [`${source} extractor succeeded.`]
|
||||
})
|
||||
}
|
||||
);
|
||||
|
||||
assert.match(
|
||||
String(result.reportPayload?.verdict?.offerGuidance),
|
||||
/daughter|student|practicality|safety/i
|
||||
);
|
||||
assert.doesNotMatch(
|
||||
String(result.reportPayload?.verdict?.offerGuidance),
|
||||
/income property|investment property/i
|
||||
);
|
||||
assert.match(
|
||||
String(result.reportPayload?.carryView?.[0]),
|
||||
/parent-risk|upkeep burden|renting/i
|
||||
);
|
||||
});
|
||||
|
||||
@@ -80,3 +80,119 @@ test("resolvePublicRecords uses Census and Texas county directory", async () =>
|
||||
assert.equal(payload.sourceIdentifierHints.parcelId, "14069438");
|
||||
assert.match(payload.lookupRecommendations.join(" "), /listing geo IDs as regional hints only/i);
|
||||
});
|
||||
|
||||
test("resolvePublicRecords falls back to coordinate geocoding when Census address lookup misses", async () => {
|
||||
const coordinatePayload = {
|
||||
result: {
|
||||
geographies: {
|
||||
States: [{ NAME: "Texas", STUSAB: "TX", STATE: "48" }],
|
||||
Counties: [{ NAME: "Nueces County", COUNTY: "355", GEOID: "48355" }],
|
||||
"2020 Census Blocks": [{ GEOID: "483550031013005" }]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const fallbackFetchText = async (url: string): Promise<string> => {
|
||||
if (url.includes("geocoding.geo.census.gov") && url.includes("onelineaddress")) {
|
||||
return JSON.stringify({ result: { addressMatches: [] } });
|
||||
}
|
||||
if (url.includes("nominatim.openstreetmap.org/search")) {
|
||||
return JSON.stringify([
|
||||
{
|
||||
lat: "27.708000",
|
||||
lon: "-97.360000",
|
||||
display_name: "1011 Ennis Joslin Rd Apt 235, Corpus Christi, TX 78412"
|
||||
}
|
||||
]);
|
||||
}
|
||||
if (url.includes("geocoding.geo.census.gov") && url.includes("geographies/coordinates")) {
|
||||
return JSON.stringify(coordinatePayload);
|
||||
}
|
||||
if (url.endsWith("/county-directory/")) {
|
||||
return countyIndexHtml;
|
||||
}
|
||||
if (url.endsWith("/county-directory/nueces.php")) {
|
||||
return countyPageHtml;
|
||||
}
|
||||
throw new Error(`Unexpected URL: ${url}`);
|
||||
};
|
||||
|
||||
const payload = await resolvePublicRecords(
|
||||
"1011 Ennis Joslin Rd APT 235, Corpus Christi, TX 78412",
|
||||
{
|
||||
fetchText: fallbackFetchText
|
||||
}
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
payload.matchedAddress,
|
||||
"1011 Ennis Joslin Rd Apt 235, Corpus Christi, TX 78412"
|
||||
);
|
||||
assert.equal(payload.county.name, "Nueces County");
|
||||
assert.equal(payload.state.code, "TX");
|
||||
assert.equal(payload.latitude, 27.708);
|
||||
assert.equal(payload.longitude, -97.36);
|
||||
assert.match(
|
||||
payload.lookupRecommendations.join(" "),
|
||||
/fallback geocoder/i
|
||||
);
|
||||
});
|
||||
|
||||
test("resolvePublicRecords retries fallback geocoding without the unit suffix", async () => {
|
||||
const seenFallbackQueries: string[] = [];
|
||||
const coordinatePayload = {
|
||||
result: {
|
||||
geographies: {
|
||||
States: [{ NAME: "Texas", STUSAB: "TX", STATE: "48" }],
|
||||
Counties: [{ NAME: "Nueces County", COUNTY: "355", GEOID: "48355" }],
|
||||
"2020 Census Blocks": [{ GEOID: "483550031013005" }]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const retryingFetchText = async (url: string): Promise<string> => {
|
||||
if (url.includes("geocoding.geo.census.gov") && url.includes("onelineaddress")) {
|
||||
return JSON.stringify({ result: { addressMatches: [] } });
|
||||
}
|
||||
if (url.includes("nominatim.openstreetmap.org/search")) {
|
||||
const query = new URL(url).searchParams.get("q") || "";
|
||||
seenFallbackQueries.push(query);
|
||||
if (query.includes("APT 235")) {
|
||||
return "[]";
|
||||
}
|
||||
if (query === "1011 Ennis Joslin Rd, Corpus Christi, TX 78412") {
|
||||
return JSON.stringify([
|
||||
{
|
||||
lat: "27.6999080",
|
||||
lon: "-97.3338107",
|
||||
display_name: "Ennis Joslin Road, Corpus Christi, Nueces County, Texas, 78412, United States"
|
||||
}
|
||||
]);
|
||||
}
|
||||
}
|
||||
if (url.includes("geocoding.geo.census.gov") && url.includes("geographies/coordinates")) {
|
||||
return JSON.stringify(coordinatePayload);
|
||||
}
|
||||
if (url.endsWith("/county-directory/")) {
|
||||
return countyIndexHtml;
|
||||
}
|
||||
if (url.endsWith("/county-directory/nueces.php")) {
|
||||
return countyPageHtml;
|
||||
}
|
||||
throw new Error(`Unexpected URL: ${url}`);
|
||||
};
|
||||
|
||||
const payload = await resolvePublicRecords(
|
||||
"1011 Ennis Joslin Rd APT 235, Corpus Christi, TX 78412",
|
||||
{
|
||||
fetchText: retryingFetchText
|
||||
}
|
||||
);
|
||||
|
||||
assert.deepEqual(seenFallbackQueries, [
|
||||
"1011 Ennis Joslin Rd APT 235, Corpus Christi, TX 78412",
|
||||
"1011 Ennis Joslin Rd, Corpus Christi, TX 78412"
|
||||
]);
|
||||
assert.equal(payload.county.name, "Nueces County");
|
||||
assert.equal(payload.state.code, "TX");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user