From a586a550c61c35ef219d798bef66470d81cdfd74 Mon Sep 17 00:00:00 2001 From: Gurnank Date: Tue, 26 Nov 2024 08:25:24 +0000 Subject: [PATCH 1/2] MAP-1883 apply query params to format and order locations --- server/data/locationClient.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/server/data/locationClient.ts b/server/data/locationClient.ts index cce6ab1d..dd684940 100644 --- a/server/data/locationClient.ts +++ b/server/data/locationClient.ts @@ -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 @@ -27,8 +27,7 @@ export default class LocationClient { ): Promise { 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`, }) } } From 8e42055b1459fc0d345cfb2796042d5e2f633b0d Mon Sep 17 00:00:00 2001 From: Gurnank Date: Tue, 26 Nov 2024 08:54:16 +0000 Subject: [PATCH 2/2] MAP-1883 update tests --- integration-tests/mockApis/locationApi.js | 6 +++--- server/data/locationClient.test.ts | 11 +++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/integration-tests/mockApis/locationApi.js b/integration-tests/mockApis/locationApi.js index 8a191c11..b6a20b90 100644 --- a/integration-tests/mockApis/locationApi.js +++ b/integration-tests/mockApis/locationApi.js @@ -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, @@ -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, @@ -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, diff --git a/server/data/locationClient.test.ts b/server/data/locationClient.test.ts index 64d7e4af..0dc09877 100644 --- a/server/data/locationClient.test.ts +++ b/server/data/locationClient.test.ts @@ -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) @@ -53,7 +53,10 @@ 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') }) }) @@ -61,7 +64,7 @@ describe('locationClient', () => { 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) @@ -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)