Skip to content

Commit

Permalink
feat(DTFS2-7052): fix address line 1 formating
Browse files Browse the repository at this point in the history
  • Loading branch information
avaitonis committed Apr 15, 2024
1 parent 837a482 commit db50210
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/modules/geospatial/geospatial.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,16 @@ describe('CustomerService', () => {

expect(response).toEqual([]);
});

it('returns addressLine1 formatted correctly even if middle value is missing', async () => {
const [modifiedOrdnanceSurveyResponse] = getAddressOrdnanceSurveyResponse;
modifiedOrdnanceSurveyResponse.results[0].DPA.BUILDING_NUMBER = null;
const address = modifiedOrdnanceSurveyResponse.results[0].DPA;
when(informaticaServiceGetAddressesByPostcode).calledWith(postcode).mockResolvedValueOnce(modifiedOrdnanceSurveyResponse);

const response = await service.getAddressesByPostcode(postcode);

expect(response[0].addressLine1).toBe(`${address.BUILDING_NAME} ${address.THOROUGHFARE_NAME}`);
});
});
});
5 changes: 3 additions & 2 deletions src/modules/geospatial/geospatial.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ export class GeospatialService {
}

response.results.forEach((item) => {
// Ordnance survey sends duplicated results with the welsh version too via 'CY'
// Item can have key DPA or LPI, get data dynamicaly, even if we expect key to always be DPA.
const item_data = item[Object.keys(item)[0]];
addresses.push({
organisationName: item_data.ORGANISATION_NAME || null,
addressLine1: `${item_data.BUILDING_NAME || ''} ${item_data.BUILDING_NUMBER || ''} ${item_data.THOROUGHFARE_NAME || ''}`.trim(),
// Filter out empty values and join values with single space.
addressLine1: [item_data.BUILDING_NAME, item_data.BUILDING_NUMBER, item_data.THOROUGHFARE_NAME].filter(Boolean).join(' '),
addressLine2: item_data.DEPENDENT_LOCALITY || null,
addressLine3: null,
locality: item_data.POST_TOWN || null,
Expand Down

0 comments on commit db50210

Please sign in to comment.