diff --git a/client/package.json b/client/package.json index 0ca6115cfa..67e0597cb9 100644 --- a/client/package.json +++ b/client/package.json @@ -38,6 +38,7 @@ "@wdio/sync": "6.10.0", "aigle": "1.14.1", "autoprefixer": "9.8.6", + "axios": "0.21.0", "ava": "3.13.0", "babel-jest": "26.6.3", "babel-loader": "8.2.1", diff --git a/client/tests/webdriver/specs/geoSearchApi.spec.js b/client/tests/webdriver/specs/geoSearchApi.spec.js new file mode 100644 index 0000000000..39ecbfa0a2 --- /dev/null +++ b/client/tests/webdriver/specs/geoSearchApi.spec.js @@ -0,0 +1,187 @@ +import { expect } from "chai" +import lodash from "lodash" + +const axios = require("axios") + +const apiUrl = `${process.env.SERVER_URL}/graphql?user=erin&pass=erin` + +// centered on General Hospital, zoom level 15, not padded +const polygon01 = + "POLYGON ((-52.77621746063233 47.56453866910163, -52.741935 47.56453866910163, -52.70763874053956 47.56453866910163, -52.70763874053956 47.571772, -52.70763874053956 47.57901543200339, -52.741935 47.57901543200339, -52.77621746063233 47.57901543200339, -52.77621746063233 47.571772, -52.77621746063233 47.56453866910163))" + +// centered on General Hospital, zoom level 15, padded by 0.5 +const polygon02 = + "POLYGON ((-52.81050682067872 47.55730028765075, -52.741935 47.55730028765075, -52.67334938049317 47.55730028765075, -52.67334938049317 47.571772, -52.67334938049317 47.58625381345426, -52.741935 47.58625381345426, -52.81050682067872 47.58625381345426, -52.81050682067872 47.571772, -52.81050682067872 47.55730028765075))" + +// centered on General Hospital, zoom level 11, padded by 0.5 +const polygon03 = + "POLYGON ((-57.13165283203125 46.642388783472754, -52.741935 46.642388783472754, -48.35357666015625 46.642388783472754, -48.35357666015625 47.571772, -48.35357666015625 48.49544709355706, -52.741935 48.49544709355706, -57.13165283203125 48.49544709355706, -57.13165283203125 47.571772, -57.13165283203125 46.642388783472754))" + +const locationQueryTemplate = { + operationName: null, + variables: { + locationQuery: { + pageSize: 0, + withinPolygon: "", + sortBy: "NAME" + } + }, + query: ` + query($locationQuery: LocationSearchQueryInput) { + locationList(query: $locationQuery) { + totalCount + list { + name + } + } + } + ` +} + +const reportQueryTemplate = { + operationName: null, + variables: { + reportQuery: { + pageSize: 0, + state: "PUBLISHED", + sortBy: "ENGAGEMENT_DATE", + withinPolygon: "" + } + }, + query: ` + query ($reportQuery: ReportSearchQueryInput) { + reportList(query: $reportQuery) { + totalCount + list { + location { + name + } + } + } + } + ` +} + +const positionQueryTemplate = { + operationName: null, + variables: { + positionQuery: { + pageSize: 0, + withinPolygon: "" + } + }, + query: ` + query ($positionQuery: PositionSearchQueryInput) { + positionList(query: $positionQuery) { + totalCount + list { + name + location { + name + } + } + } + } + ` +} + +describe("Location geo search, when map center is (-52.741935 47.571772)", () => { + it("should return one location for visible map bounds", async() => { + const query = lodash.cloneDeep(locationQueryTemplate) + query.variables.locationQuery.withinPolygon = polygon01 + const result = await axios.post(apiUrl, query) + expect(result?.status).to.equal(200) + + const resultList = result?.data?.data?.locationList?.list || [] + expect(resultList.length).to.equal(1) + expect(resultList[0].name).to.equal("General Hospital") + }) + + const locations01 = [ + "Cabot Tower", + "Fort Amherst", + "General Hospital", + "Murray's Hotel", + "Wishingwells Park" + ] + + it("should return 5 locations for padded (0.5) map bounds", async() => { + const query = lodash.cloneDeep(locationQueryTemplate) + query.variables.locationQuery.withinPolygon = polygon02 + const result = await axios.post(apiUrl, query) + expect(result?.status).to.equal(200) + + const resultList = result?.data?.data?.locationList?.list || [] + expect(resultList.length).to.equal(5) + expect(resultList[0].name).to.equal(locations01[0]) + expect(resultList[1].name).to.equal(locations01[1]) + expect(resultList[2].name).to.equal(locations01[2]) + expect(resultList[3].name).to.equal(locations01[3]) + expect(resultList[4].name).to.equal(locations01[4]) + }) + + it("should return 9 locations in zoom level 11 for padded (0.5) map bounds", async() => { + const query = lodash.cloneDeep(locationQueryTemplate) + query.variables.locationQuery.withinPolygon = polygon03 + const result = await axios.post(apiUrl, query) + expect(result?.status).to.equal(200) + + const resultList = result?.data?.data?.locationList?.list || [] + expect(resultList.length).to.equal(9) + expect(resultList[0].name).to.equal("Cabot Tower") + expect(resultList[1].name).to.equal("Conception Bay South Police Station") + expect(resultList[2].name).to.equal("Fort Amherst") + expect(resultList[3].name).to.equal("General Hospital") + expect(resultList[4].name).to.equal("Harbour Grace Police Station") + expect(resultList[5].name).to.equal("Murray's Hotel") + expect(resultList[6].name).to.equal("Portugal Cove Ferry Terminal") + expect(resultList[7].name).to.equal("St Johns Airport") + expect(resultList[8].name).to.equal("Wishingwells Park") + }) + + it("should return reports in only General Hospital for visible map bounds", async() => { + const query = lodash.cloneDeep(reportQueryTemplate) + query.variables.reportQuery.withinPolygon = polygon01 + const result = await axios.post(apiUrl, query) + expect(result?.status).to.equal(200) + + const resultList = result?.data?.data?.reportList?.list || [] + expect(resultList.length).to.be.gt(1) + expect( + resultList.every(r => r.location.name === "General Hospital") + ).to.equal(true) + }) + + it(`should return reports from any of "${locations01.join()}" for padded (0.5) map bounds`, async() => { + const query = lodash.cloneDeep(reportQueryTemplate) + query.variables.reportQuery.withinPolygon = polygon02 + const result = await axios.post(apiUrl, query) + expect(result?.status).to.equal(200) + + const resultList = result?.data?.data?.reportList?.list || [] + expect(resultList.length).to.be.gt(1) + resultList.forEach(r => expect(r.location.name).to.be.oneOf(locations01)) + }) + + it("shouldn't return any positions for visible map bounds", async() => { + const query = lodash.cloneDeep(positionQueryTemplate) + query.variables.positionQuery.withinPolygon = polygon01 + const result = await axios.post(apiUrl, query) + expect(result?.status).to.equal(200) + + const resultList = result?.data?.data?.positionList?.list || [] + expect(resultList.length).to.equal(0) + }) + + it("should return one position for padded map bounds", async() => { + const query = lodash.cloneDeep(positionQueryTemplate) + query.variables.positionQuery.withinPolygon = polygon02 + const result = await axios.post(apiUrl, query) + expect(result?.status).to.equal(200) + + const resultList = result?.data?.data?.positionList?.list || [] + expect(resultList.length).to.equal(1) + expect(resultList[0].name).to.equal("Planning Captain") + expect(resultList[0].location.name).to.equal("Wishingwells Park") + }) +}) diff --git a/client/yarn.lock b/client/yarn.lock index bb245e89d4..784afc487e 100644 --- a/client/yarn.lock +++ b/client/yarn.lock @@ -4286,6 +4286,13 @@ axe-core@^4.0.2: resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.0.2.tgz#c7cf7378378a51fcd272d3c09668002a4990b1cb" integrity sha512-arU1h31OGFu+LPrOLGZ7nB45v940NMDMEJeNmbutu57P+UFDVnkZg3e+J1I2HJRZ9hT7gO8J91dn/PMrAiKakA== +axios@0.21.0: + version "0.21.0" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.0.tgz#26df088803a2350dff2c27f96fef99fe49442aca" + integrity sha512-fmkJBknJKoZwem3/IKSSLpkdNXZeBu5Q7GA/aRsr2btgrptmSCxi2oFjZHqGdK9DoTil9PIHlPIZw2EcRJXRvw== + dependencies: + follow-redirects "^1.10.0" + axios@^0.19.2: version "0.19.2" resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.2.tgz#3ea36c5d8818d0d5f8a8a97a6d36b86cdc00cb27" @@ -8555,7 +8562,7 @@ follow-redirects@1.5.10: dependencies: debug "=3.1.0" -follow-redirects@^1.0.0: +follow-redirects@^1.0.0, follow-redirects@^1.10.0: version "1.13.0" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.0.tgz#b42e8d93a2a7eea5ed88633676d6597bc8e384db" integrity sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA== diff --git a/insertBaseData-mssql.sql b/insertBaseData-mssql.sql index 1311aa11f1..d118b965f4 100644 --- a/insertBaseData-mssql.sql +++ b/insertBaseData-mssql.sql @@ -554,6 +554,7 @@ INSERT INTO positionRelationships (positionUuid_a, positionUuid_b, createdAt, up UPDATE positions SET locationUuid = (SELECT uuid from LOCATIONS where name = 'Kabul Police Academy') WHERE name = 'Chief of Police'; UPDATE positions SET locationUuid = (SELECT uuid from LOCATIONS where name = 'MoD Headquarters Kabul') WHERE name = 'Cost Adder - MoD'; +UPDATE positions SET locationUuid = (SELECT uuid from LOCATIONS where name = 'Wishingwells Park') WHERE name = 'Planning Captain'; --Write a couple reports! DECLARE @reportUuid varchar(36);