Skip to content

Commit

Permalink
MAP-1883 apply query params to format and order locations (#738)
Browse files Browse the repository at this point in the history
* MAP-1883 apply query params to format and order locations

* MAP-1883 update tests
  • Loading branch information
GurnankCheema authored Nov 26, 2024
1 parent 30b3b1e commit 0a03641
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
6 changes: 3 additions & 3 deletions integration-tests/mockApis/locationApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
return stubFor({
request: {
method: 'GET',
urlPattern: `/location-api/locations/${incidentLocationId}`,
urlPattern: `/location-api/locations/${incidentLocationId}\\?formatLocalName=true`,
},
response: {
status: 200,
Expand All @@ -25,7 +25,7 @@ module.exports = {
return stubFor({
request: {
method: 'GET',
urlPattern: `/location-api/locations/${incidentLocationId}`,
urlPattern: `/location-api/locations/${incidentLocationId}\\?formatLocalName=true`,
},
response: {
status: 404,
Expand All @@ -37,7 +37,7 @@ module.exports = {
return stubFor({
request: {
method: 'GET',
urlPattern: `/location-api/locations/prison/${prisonId}/non-residential-usage-type/${usageType}`,
urlPattern: `/location-api/locations/prison/${prisonId}/non-residential-usage-type/${usageType}\\?formatLocalName=true&sortByLocalName=true`,
},
response: {
status: 200,
Expand Down
11 changes: 7 additions & 4 deletions server/data/locationClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('locationClient', () => {
key: 'MDI-CELL-A',
}
fakeLocationApi
.get(`/locations/${locationId}`)
.get(`/locations/${locationId}?formatLocalName=true`)
.matchHeader('authorization', `Bearer ${token}`)
.reply(200, location)

Expand All @@ -53,15 +53,18 @@ describe('locationClient', () => {
})

it('should throw for non-404 errors', async () => {
fakeLocationApi.get(`/locations/${locationId}`).matchHeader('authorization', `Bearer ${token}`).reply(400)
fakeLocationApi
.get(`/locations/${locationId}?formatLocalName=true`)
.matchHeader('authorization', `Bearer ${token}`)
.reply(400)
await expect(locationClient.getLocation(locationId)).rejects.toThrow('Bad Request')
})
})
describe('getLocations', () => {
const locations = []
it('should return data from api', async () => {
fakeLocationApi
.get('/locations/prison/MDI/non-residential-usage-type/OCCURRENCE')
.get('/locations/prison/MDI/non-residential-usage-type/OCCURRENCE?formatLocalName=true&sortByLocalName=true')
.matchHeader('authorization', `Bearer ${token}`)
.reply(200, locations)

Expand All @@ -70,7 +73,7 @@ describe('locationClient', () => {
})
it('can not search with incorrect usage-type filter', async () => {
fakeLocationApi
.get('/locations/prison/MDI/non-residential-usage-type/SOME-TYPE')
.get('/locations/prison/MDI/non-residential-usage-type/SOME-TYPE?formatLocalName=true&sortByLocalName=true')
.matchHeader('authorization', `Bearer ${token}`)
.reply(400)

Expand Down
5 changes: 2 additions & 3 deletions server/data/locationClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class LocationClient {
}
try {
logger.info(`Location Client getting details for location: ${incidentLocationId}`)
const result = await this.restClient.get({ path: `/locations/${incidentLocationId}` })
const result = await this.restClient.get({ path: `/locations/${incidentLocationId}?formatLocalName=true` })
return result as LocationInPrison
} catch (error) {
if (error?.status !== 404) throw error
Expand All @@ -27,8 +27,7 @@ export default class LocationClient {
): Promise<LocationInPrison[]> {
logger.info(`getting locations for prison ${prisonId} and usageType ${usageType}`)
return this.restClient.get({
path: `/locations/prison/${prisonId}/non-residential-usage-type/${usageType}`,
headers: { 'Sort-Fields': 'userDescription' },
path: `/locations/prison/${prisonId}/non-residential-usage-type/${usageType}?formatLocalName=true&sortByLocalName=true`,
})
}
}

0 comments on commit 0a03641

Please sign in to comment.