Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/2024 01 26 #659

Merged
merged 3 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions backend/core/src/applications/services/applications.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,17 @@ export class ApplicationsService {
return await applicationsRepository.findOne({ where: { id: newApplication.id } })
}
)

const listing = await this.listingsService.findOne(application.listingId)

// Calculate geocoding preferences after save
if (listing.jurisdiction?.enableGeocodingPreferences) {
try {
void this.geocodingService.validateGeocodingPreferences(application, listing)
} catch (e) {
console.warn("error while validating geocoding preferences")
}
}
return app
}

Expand Down
212 changes: 170 additions & 42 deletions backend/core/src/applications/services/geocoding.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Listing } from "../../listings/entities/listing.entity"
import { InputType } from "../../shared/types/input-type"
import { MapLayer } from "../../map-layers/entities/map-layer.entity"
import { FeatureCollection } from "@turf/helpers"
import { ApplicationMultiselectQuestion } from "../entities/application-multiselect-question.entity"

describe("GeocodingService", () => {
let service: GeocodingService
Expand Down Expand Up @@ -175,7 +176,7 @@ describe("GeocodingService", () => {
multiselectQuestion: {
options: [
{
text: "Geocoding option by radius",
text: "Geocoding option by Radius",
collectAddress: true,
radiusSize: 5,
validationMethod: ValidationMethod.radius,
Expand All @@ -186,54 +187,46 @@ describe("GeocodingService", () => {
],
}
const preferenceAddress = { ...address, latitude: 38.89485, longitude: -77.04251 }
const application = {
id: "applicationId",
preferences: [
const preferences = [
{
key: "Geocoding preference",
options: [
{
key: "Geocoding option by Radius",
checked: true,
extraData: [
{
type: InputType.address,
value: preferenceAddress,
},
],
},
],
},
]
it("should save the validated value as extraData", () => {
const response = service.validateRadiusPreferences(
(preferences as unknown) as ApplicationMultiselectQuestion[],
listing as Listing
)
expect(response).toEqual([
{
key: "Geocoding preference",
options: [
{
key: "Geocoding option by radius",
key: "Geocoding option by Radius",
checked: true,
extraData: [
{
type: InputType.address,
value: preferenceAddress,
},
{ key: "geocodingVerified", type: InputType.text, value: "true" },
],
},
],
},
],
}
it("should save the validated value as extraData", async () => {
await service.validateRadiusPreferences(
(application as unknown) as Application,
listing as Listing
)
expect(applicationRepoUpdate).toBeCalledWith(
{ id: "applicationId" },
{
preferences: expect.arrayContaining([
expect.objectContaining({
key: "Geocoding preference",
options: [
{
checked: true,
extraData: [
{
type: "address",
value: preferenceAddress,
},
{ key: "geocodingVerified", type: "text", value: "true" },
],
key: "Geocoding option by radius",
},
],
}),
]),
}
)
])
})
})
describe("validateGeoLayerPreferences", () => {
Expand All @@ -255,9 +248,28 @@ describe("GeocodingService", () => {
],
}
const preferenceAddress = { ...address, latitude: 38.89485, longitude: -77.04251 }
const application = {
id: "applicationId",
preferences: [

const preference = {
key: "Geocoding preference",
options: [
{
key: "Geocoding option by map",
checked: true,
extraData: [
{
type: InputType.address,
value: preferenceAddress,
},
],
},
],
}
it("should save the validated value as extraData for map layer", async () => {
const response = await service.validateGeoLayerPreferences(
([preference] as unknown) as ApplicationMultiselectQuestion[],
listing as Listing
)
expect(response).toEqual([
{
key: "Geocoding preference",
options: [
Expand All @@ -269,23 +281,114 @@ describe("GeocodingService", () => {
type: InputType.address,
value: preferenceAddress,
},
{ key: "geocodingVerified", type: InputType.text, value: "true" },
],
},
],
},
])
})
})
describe("validateGeocodingPreferences", () => {
const listing = {
buildingAddress: address,
listingMultiselectQuestions: [
{
multiselectQuestion: {
options: [
{
text: "Geocoding option by radius",
collectAddress: true,
radiusSize: 5,
validationMethod: ValidationMethod.radius,
},
],
},
},
{
multiselectQuestion: {
options: [
{
text: "Geocoding option by map",
collectAddress: true,
mapLayerId: "mapLayerId",
validationMethod: ValidationMethod.map,
},
],
},
},
{
multiselectQuestion: {
options: [
{
text: "non-geocoding option",
},
],
},
},
],
}
it("should save the validated value as extraData for map layer", async () => {
await service.validateGeoLayerPreferences(

const preferenceAddress = { ...address, latitude: 38.89485, longitude: -77.04251 }
const preferences = [
{
key: "Geocoding preference by map",
options: [
{
key: "Geocoding option by map",
checked: true,
extraData: [
{
type: InputType.address,
value: preferenceAddress,
},
],
},
],
},
{
key: "Geocoding preference by radius",
options: [
{
key: "Geocoding option by radius",
checked: true,
extraData: [
{
type: InputType.address,
value: preferenceAddress,
},
],
},
],
},
{
key: "non-geocoding preference",
options: [
{
key: "non-geocoding option",
checked: true,
},
],
},
]

const application = {
id: "applicationId",
preferences: preferences,
}

it("should save all updated preferences", async () => {
await service.validateGeocodingPreferences(
(application as unknown) as Application,
listing as Listing
(listing as unknown) as Listing
)

expect(applicationRepoUpdate).toBeCalledWith(
{ id: "applicationId" },
{
preferences: expect.arrayContaining([
expect.objectContaining({
key: "Geocoding preference",
key: "Geocoding preference by map",
options: [
{
checked: true,
Expand All @@ -300,6 +403,31 @@ describe("GeocodingService", () => {
},
],
}),
expect.objectContaining({
key: "Geocoding preference by radius",
options: [
{
checked: true,
extraData: [
{
type: "address",
value: preferenceAddress,
},
{ key: "geocodingVerified", type: "text", value: "true" },
],
key: "Geocoding option by radius",
},
],
}),
expect.objectContaining({
key: "non-geocoding preference",
options: [
{
checked: true,
key: "non-geocoding option",
},
],
}),
]),
}
)
Expand Down
Loading
Loading