Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAP-1883 apply query params to format and order locations #738

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`,
})
}
}
Loading