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

FCRM-4507 removed all references to removed getByPoint service #381

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 1 addition & 5 deletions server/routes/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ module.exports = {
let vector

// Always get Flood zone as flood zone is provided in the request if not provided.
if (polygon) {
zone = await riskService.getByPolygon(util.convertToGeoJson(polygon))
} else {
zone = await riskService.getByPoint(center[0], center[1])
}
zone = await riskService.getByPolygon(util.convertToGeoJson(polygon))
const floodZone = new FloodZone(zone)
zone = floodZone.zone

Expand Down
20 changes: 2 additions & 18 deletions server/services/risk.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,11 @@
const util = require('../util')
const config = require('../../config')
const url = config.service + '/zones'
const urlByPolygon = config.service + '/zones-by-polygon'
const getAreaPolygon = require('area-polygon')

const getByPoint = (easting, northing) => {
if (!easting || !northing) {
throw new Error('No Point provided')
}

return util.getJson(`${url}/${easting}/${northing}/1`)
}
const getByPolygon = (polygon) => {
if (!polygon) {
throw new Error('No Polygon provided')
}
const { coordinates = [] } = JSON.parse(polygon)

const area = getAreaPolygon(coordinates[0])
if (area === 0 || area === '0') {
return getByPoint(coordinates[0][0][0], coordinates[0][0][1])
} else {
return util.getJson(`${urlByPolygon}?polygon=${polygon}`)
}
return util.getJson(`${urlByPolygon}?polygon=${polygon}`)
}
module.exports = { getByPoint, getByPolygon }
module.exports = { getByPolygon }
3 changes: 0 additions & 3 deletions test/routes/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ const config = require('../../config')
lab.experiment('PDF', () => {
let server
let restoreGetByPolygon
let restoreGetByPoint
let restoreWreckPost

lab.before(async () => {
restoreGetByPolygon = riskService.getByPolygon
restoreGetByPoint = riskService.getByPoint

riskService.getByPolygon = () => ({ in_england: true })
riskService.getByPoint = () => ({ point_in_england: true })
Expand All @@ -26,7 +24,6 @@ lab.experiment('PDF', () => {

lab.after(async () => {
riskService.getByPolygon = restoreGetByPolygon
riskService.getByPoint = restoreGetByPoint
Wreck.post = restoreWreckPost
await server.stop()
})
Expand Down
43 changes: 1 addition & 42 deletions test/services/risk.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const Lab = require('@hapi/lab')
const Code = require('@hapi/code')
const lab = exports.lab = Lab.script()
const { getByPoint, getByPolygon } = require('../../server/services/risk')
const { getByPolygon } = require('../../server/services/risk')
const util = require('../../server/util')
const config = require('../../config')

Expand All @@ -17,39 +17,6 @@ lab.experiment('risk', () => {
util.getJson = restoreGetJson
})

lab.test('getByPoint without easting or northing should throw "No Point provided"', async () => {
const point = {}
try {
await getByPoint(point.easting, point.northing)
} catch (err) {
Code.expect(getByPoint).to.throw(Error, 'No Point provided')
}
})

lab.test('getByPoint without easting should throw "No Point provided"', async () => {
const point = { northing: 388244 }
try {
await getByPoint(point.easting, point.northing)
} catch (err) {
Code.expect(getByPoint).to.throw(Error, 'No Point provided')
}
})

lab.test('getByPoint without northing should throw "No Point provided"', async () => {
const point = { easting: 388244 }
try {
await getByPoint(point.easting, point.northing)
} catch (err) {
Code.expect(getByPoint).to.throw(Error, 'No Point provided')
}
})

lab.test('getByPoint with northing and easting should call util.getJson"', async () => {
const point = { easting: 123456, northing: 78910 }
const response = await getByPoint(point.easting, point.northing)
Code.expect(response).to.equal(`${config.service}/zones/123456/78910/1`)
})

lab.test('getByPolygon without polygon should throw "No Polygon provided"', async () => {
try {
const response = await getByPolygon()
Expand All @@ -67,12 +34,4 @@ lab.experiment('risk', () => {
const response = await getByPolygon(polygon)
Code.expect(response).to.equal(`${config.service}/zones-by-polygon?polygon=${polygon}`)
})

lab.test('getByPolygon with a polygon of zero area should call getByPoint', async () => {
// FCRM-3961 - if a call is made to getByPolygon and the polygon has no area (ie the user clicked the same spot 4 times)
// then the postgres call fails. To mitigate this, we should treat the polygon as a point in these circumstances.
const polygon = '{"type": "Polygon", "coordinates": [[[479826,484054],[479826,484054],[479826,484054],[479826,484054]]]}'
const response = await getByPolygon(polygon)
Code.expect(response).to.equal(`${config.service}/zones/479826/484054/1`)
})
})
Loading