Skip to content

Commit

Permalink
#3043: Add e2e api tests for geosearch queries
Browse files Browse the repository at this point in the history
  • Loading branch information
ysf-simsoft committed Aug 22, 2020
1 parent 29cc7bd commit 7d5fd43
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 1 deletion.
1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
187 changes: 187 additions & 0 deletions client/tests/webdriver/specs/geoSearchApi.spec.js
Original file line number Diff line number Diff line change
@@ -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")
})
})
9 changes: 8 additions & 1 deletion client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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==
Expand Down
1 change: 1 addition & 0 deletions insertBaseData-mssql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7d5fd43

Please sign in to comment.