From 7d5fd431ae1cb0f2d193e638f02b291d5aeb528e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20Co=C5=9Fkun?= Date: Thu, 25 Jun 2020 20:42:25 +0300 Subject: [PATCH] nci-agency/anet#3043: Add e2e api tests for geosearch queries --- client/package.json | 1 + .../webdriver/specs/geoSearchApi.spec.js | 187 ++++++++++++++++++ client/yarn.lock | 9 +- insertBaseData-mssql.sql | 1 + 4 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 client/tests/webdriver/specs/geoSearchApi.spec.js diff --git a/client/package.json b/client/package.json index 1a9d61b0e62..ecb4e2abbbc 100644 --- a/client/package.json +++ b/client/package.json @@ -36,6 +36,7 @@ "aigle": "1.14.1", "autoprefixer": "9.8.6", "ava": "3.11.1", + "axios": "0.20.0", "babel-jest": "26.3.0", "babel-loader": "8.1.0", "babel-preset-react-app": "9.1.2", diff --git a/client/tests/webdriver/specs/geoSearchApi.spec.js b/client/tests/webdriver/specs/geoSearchApi.spec.js new file mode 100644 index 00000000000..39ecbfa0a2f --- /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 d0aafcf404c..4e0f1fd0286 100644 --- a/client/yarn.lock +++ b/client/yarn.lock @@ -3733,6 +3733,13 @@ axe-core@^3.5.4: resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-3.5.5.tgz#84315073b53fa3c0c51676c588d59da09a192227" integrity sha512-5P0QZ6J5xGikH780pghEdbEKijCTrruK9KxtPZCFWUpef0f6GipO+xEZ5GKCb020mmqgbiNO6TcA55CriL784Q== +axios@0.20.0: + version "0.20.0" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.20.0.tgz#057ba30f04884694993a8cd07fa394cff11c50bd" + integrity sha512-ANA4rr2BDcmmAQLOKft2fufrtuvlqR+cXNNinUmvfeSNCOF98PZL+7M/v1zIdGo7OLjEA9J2gXJL+j4zGsl0bA== + 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" @@ -7691,7 +7698,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 68ffd7c958d..3f8efc1ae84 100644 --- a/insertBaseData-mssql.sql +++ b/insertBaseData-mssql.sql @@ -539,6 +539,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);