Skip to content

Commit

Permalink
FCRM-4507 removed all references to removed getByPoint service
Browse files Browse the repository at this point in the history
  • Loading branch information
markfee committed Nov 21, 2023
1 parent 145136a commit 0c3d5b1
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 68 deletions.
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`)
})
})

0 comments on commit 0c3d5b1

Please sign in to comment.