diff --git a/src/modules/geospatial/geospatial.controller.test.ts b/src/modules/geospatial/geospatial.controller.test.ts index aca862af..d125cf04 100644 --- a/src/modules/geospatial/geospatial.controller.test.ts +++ b/src/modules/geospatial/geospatial.controller.test.ts @@ -12,7 +12,7 @@ describe('GeospatialController', () => { let controller: GeospatialController; const valueGenerator = new RandomValueGenerator(); - const { getAddressByPostcodeResponse, getAddressByPostcodeMultipleResponse } = new GetGeospatialAddressesGenerator(valueGenerator).generate({ + const { getAddressesByPostcodeResponse, getAddressesByPostcodeMultipleResponse } = new GetGeospatialAddressesGenerator(valueGenerator).generate({ numberToGenerate: 2, }); @@ -33,21 +33,21 @@ describe('GeospatialController', () => { const postcode = GEOSPATIAL.EXAMPLES.POSTCODE; it('returns a single address for the postcode when the service returns a single address', async () => { - when(geospatialServiceGetAddressesByPostcode).calledWith(postcode).mockResolvedValueOnce(getAddressByPostcodeResponse[0]); + when(geospatialServiceGetAddressesByPostcode).calledWith(postcode).mockResolvedValueOnce(getAddressesByPostcodeResponse[0]); const response = await controller.getAddressesByPostcode({ postcode }); expect(geospatialServiceGetAddressesByPostcode).toHaveBeenCalledTimes(1); - expect(response).toEqual(getAddressByPostcodeResponse[0]); + expect(response).toEqual(getAddressesByPostcodeResponse[0]); }); it('returns multiple addresses for the postcode when the service returns multiple addresses', async () => { - when(geospatialServiceGetAddressesByPostcode).calledWith(postcode).mockResolvedValueOnce(getAddressByPostcodeMultipleResponse); + when(geospatialServiceGetAddressesByPostcode).calledWith(postcode).mockResolvedValueOnce(getAddressesByPostcodeMultipleResponse); const response = await controller.getAddressesByPostcode({ postcode }); expect(geospatialServiceGetAddressesByPostcode).toHaveBeenCalledTimes(1); - expect(response).toEqual(getAddressByPostcodeMultipleResponse); + expect(response).toEqual(getAddressesByPostcodeMultipleResponse); }); it('returns an empty response for the postcode when the service returns an empty response', async () => { diff --git a/src/modules/geospatial/geospatial.service.test.ts b/src/modules/geospatial/geospatial.service.test.ts index 1cd89fdb..1718118f 100644 --- a/src/modules/geospatial/geospatial.service.test.ts +++ b/src/modules/geospatial/geospatial.service.test.ts @@ -30,34 +30,34 @@ describe('GeospatialService', () => { describe('getAddressesByPostcode', () => { const { - getAddressByPostcodeResponse, - getAddressByPostcodeMultipleResponse, - getAddressOrdnanceSurveyResponse, - getAddressOrdnanceSurveyMultipleResponse, - getAddressOrdnanceSurveyEmptyResponse, + getAddressesByPostcodeResponse, + getAddressesByPostcodeMultipleResponse, + getAddressesOrdnanceSurveyResponse, + getAddressesOrdnanceSurveyMultipleMatchingAddressesResponse, + getAddressesOrdnanceSurveyEmptyResponse, } = new GetGeospatialAddressesGenerator(valueGenerator).generate({ numberToGenerate: 2, }); - const postcode = getAddressByPostcodeResponse[0][0].postalCode; + const postcode = getAddressesByPostcodeResponse[0][0].postalCode; it('returns a single address from the backend service', async () => { - when(ordnanceSurveyServiceGetAddressesByPostcode).calledWith(postcode).mockResolvedValueOnce(getAddressOrdnanceSurveyResponse[0]); + when(ordnanceSurveyServiceGetAddressesByPostcode).calledWith(postcode).mockResolvedValueOnce(getAddressesOrdnanceSurveyResponse[0]); const response = await service.getAddressesByPostcode(postcode); - expect(response).toEqual(getAddressByPostcodeResponse[0]); + expect(response).toEqual(getAddressesByPostcodeResponse[0]); }); it('returns multiple addressess from the backend service', async () => { - when(ordnanceSurveyServiceGetAddressesByPostcode).calledWith(postcode).mockResolvedValueOnce(getAddressOrdnanceSurveyMultipleResponse); + when(ordnanceSurveyServiceGetAddressesByPostcode).calledWith(postcode).mockResolvedValueOnce(getAddressesOrdnanceSurveyMultipleMatchingAddressesResponse); const response = await service.getAddressesByPostcode(postcode); - expect(response).toEqual(getAddressByPostcodeMultipleResponse); + expect(response).toEqual(getAddressesByPostcodeMultipleResponse); }); it('can handle empty backend response', async () => { - when(ordnanceSurveyServiceGetAddressesByPostcode).calledWith(postcode).mockResolvedValueOnce(getAddressOrdnanceSurveyEmptyResponse[0]); + when(ordnanceSurveyServiceGetAddressesByPostcode).calledWith(postcode).mockResolvedValueOnce(getAddressesOrdnanceSurveyEmptyResponse[0]); const response = await service.getAddressesByPostcode(postcode); @@ -65,7 +65,7 @@ describe('GeospatialService', () => { }); it('returns addressLine1 formatted correctly even if middle value is missing', async () => { - const [modifiedOrdnanceSurveyResponse] = structuredClone(getAddressOrdnanceSurveyResponse); + const [modifiedOrdnanceSurveyResponse] = structuredClone(getAddressesOrdnanceSurveyResponse); modifiedOrdnanceSurveyResponse.results[0].DPA.BUILDING_NUMBER = null; const address = modifiedOrdnanceSurveyResponse.results[0].DPA; when(ordnanceSurveyServiceGetAddressesByPostcode).calledWith(postcode).mockResolvedValueOnce(modifiedOrdnanceSurveyResponse); diff --git a/test/geospatial/get-address-by-postcode.api-test.ts b/test/geospatial/get-address-by-postcode.api-test.ts index 081fadb7..37002809 100644 --- a/test/geospatial/get-address-by-postcode.api-test.ts +++ b/test/geospatial/get-address-by-postcode.api-test.ts @@ -12,13 +12,13 @@ describe('GET /geospatial/addresses/postcode?postcode=', () => { let api: Api; const { - ordnanceSurveyPath, - mdmPath, - getAddressByPostcodeResponse, - getAddressByPostcodeMultipleResponse, - getAddressOrdnanceSurveyResponse, - getAddressOrdnanceSurveyEmptyResponse, - getAddressOrdnanceSurveyMultipleResponse, + ordnanceSurveyPaths, + mdmPaths, + getAddressesByPostcodeResponse, + getAddressesByPostcodeMultipleResponse, + getAddressesOrdnanceSurveyResponse, + getAddressesOrdnanceSurveyEmptyResponse, + getAddressesOrdnanceSurveyMultipleMatchingAddressesResponse, ordnanceSurveyAuthErrorResponse, } = new GetGeospatialAddressesGenerator(valueGenerator).generate({ postcode: GEOSPATIAL.EXAMPLES.POSTCODE, @@ -44,42 +44,42 @@ describe('GET /geospatial/addresses/postcode?postcode=', () => { // MDM auth tests withClientAuthenticationTests({ givenTheRequestWouldOtherwiseSucceed: () => { - requestToGetAddressesByPostcode(ordnanceSurveyPath[0]).reply(200, getAddressOrdnanceSurveyResponse[0]); + requestToGetAddressesByPostcode(ordnanceSurveyPaths[0]).reply(200, getAddressesOrdnanceSurveyResponse[0]); }, - makeRequestWithoutAuth: (incorrectAuth?: IncorrectAuthArg) => api.getWithoutAuth(mdmPath[0], incorrectAuth?.headerName, incorrectAuth?.headerValue), + makeRequestWithoutAuth: (incorrectAuth?: IncorrectAuthArg) => api.getWithoutAuth(mdmPaths[0], incorrectAuth?.headerName, incorrectAuth?.headerValue), }); it('returns a 200 response with the address if it is returned by Ordnance Survey API', async () => { - requestToGetAddressesByPostcode(ordnanceSurveyPath[0]).reply(200, getAddressOrdnanceSurveyResponse[0]); + requestToGetAddressesByPostcode(ordnanceSurveyPaths[0]).reply(200, getAddressesOrdnanceSurveyResponse[0]); - const { status, body } = await api.get(mdmPath[0]); + const { status, body } = await api.get(mdmPaths[0]); expect(status).toBe(200); - expect(body).toStrictEqual(getAddressByPostcodeResponse[0]); + expect(body).toStrictEqual(getAddressesByPostcodeResponse[0]); }); it('returns a 200 response with the addresses if they are returned by Ordnance Survey API', async () => { - requestToGetAddressesByPostcode(ordnanceSurveyPath[0]).reply(200, getAddressOrdnanceSurveyMultipleResponse); + requestToGetAddressesByPostcode(ordnanceSurveyPaths[0]).reply(200, getAddressesOrdnanceSurveyMultipleMatchingAddressesResponse); - const { status, body } = await api.get(mdmPath[0]); + const { status, body } = await api.get(mdmPaths[0]); expect(status).toBe(200); - expect(body).toStrictEqual(getAddressByPostcodeMultipleResponse); + expect(body).toStrictEqual(getAddressesByPostcodeMultipleResponse); }); it('returns an empty 200 response if Ordnance Survey API returns a 200 without results', async () => { - requestToGetAddressesByPostcode(ordnanceSurveyPath[0]).reply(200, getAddressOrdnanceSurveyEmptyResponse[0]); + requestToGetAddressesByPostcode(ordnanceSurveyPaths[0]).reply(200, getAddressesOrdnanceSurveyEmptyResponse[0]); - const { status, body } = await api.get(mdmPath[0]); + const { status, body } = await api.get(mdmPaths[0]); expect(status).toBe(200); expect(body).toStrictEqual([]); }); it('returns a 500 response if Ordnance Survey API returns a status code 401', async () => { - requestToGetAddressesByPostcode(ordnanceSurveyPath[0]).reply(401); + requestToGetAddressesByPostcode(ordnanceSurveyPaths[0]).reply(401); - const { status, body } = await api.get(mdmPath[0]); + const { status, body } = await api.get(mdmPaths[0]); expect(status).toBe(500); expect(body).toStrictEqual({ @@ -89,9 +89,9 @@ describe('GET /geospatial/addresses/postcode?postcode=', () => { }); it('returns a 500 response if Ordnance Survey API returns a status code 404', async () => { - requestToGetAddressesByPostcode(ordnanceSurveyPath[0]).reply(404); + requestToGetAddressesByPostcode(ordnanceSurveyPaths[0]).reply(404); - const { status, body } = await api.get(mdmPath[0]); + const { status, body } = await api.get(mdmPaths[0]); expect(status).toBe(500); expect(body).toStrictEqual({ @@ -101,9 +101,9 @@ describe('GET /geospatial/addresses/postcode?postcode=', () => { }); it('returns a 500 response if Ordnance Survey API times out', async () => { - requestToGetAddressesByPostcode(ordnanceSurveyPath[0]).delay(TIME_EXCEEDING_ORDNANCE_SURVEY_TIMEOUT).reply(200, getAddressOrdnanceSurveyResponse[0]); + requestToGetAddressesByPostcode(ordnanceSurveyPaths[0]).delay(TIME_EXCEEDING_ORDNANCE_SURVEY_TIMEOUT).reply(200, getAddressesOrdnanceSurveyResponse[0]); - const { status, body } = await api.get(mdmPath[0]); + const { status, body } = await api.get(mdmPaths[0]); expect(status).toBe(500); expect(body).toStrictEqual({ @@ -113,9 +113,9 @@ describe('GET /geospatial/addresses/postcode?postcode=', () => { }); it('returns a 500 response if Ordnance Survey API returns error', async () => { - requestToGetAddressesByPostcode(ordnanceSurveyPath[0]).reply(401, ordnanceSurveyAuthErrorResponse); + requestToGetAddressesByPostcode(ordnanceSurveyPaths[0]).reply(401, ordnanceSurveyAuthErrorResponse); - const { status, body } = await api.get(mdmPath[0]); + const { status, body } = await api.get(mdmPaths[0]); expect(status).toBe(500); expect(body).toStrictEqual({ diff --git a/test/support/generator/get-geospatial-addresses-generator.ts b/test/support/generator/get-geospatial-addresses-generator.ts index 51522d9f..02102b34 100644 --- a/test/support/generator/get-geospatial-addresses-generator.ts +++ b/test/support/generator/get-geospatial-addresses-generator.ts @@ -189,13 +189,13 @@ export class GetGeospatialAddressesGenerator extends AbstractGenerator