diff --git a/backend/server/routes/reports/deleteReport/report.js b/backend/server/routes/reports/deleteReport/report.js index bd36a7a5ee..70855c2edd 100644 --- a/backend/server/routes/reports/deleteReport/report.js +++ b/backend/server/routes/reports/deleteReport/report.js @@ -93,7 +93,7 @@ const fillData = (reportData, laData, WS1) => { la = laData[establishment.id].cssrRecord.localAuthority; } const address = concatenateAddress( - establishment.address, + establishment.address1, establishment.address2, establishment.address3, establishment.town, @@ -161,4 +161,5 @@ const generateDeleteReport = async (req, res) => { module.exports = router; module.exports.generateDeleteReport = generateDeleteReport; +module.exports.fillData = fillData; module.exports.monthsWithoutUpdate = monthsWithoutUpdate; diff --git a/backend/server/test/factories/deleteReport/deleteReport.js b/backend/server/test/factories/deleteReport/deleteReport.js index 4c8c2cba06..fa7c6c9ca6 100644 --- a/backend/server/test/factories/deleteReport/deleteReport.js +++ b/backend/server/test/factories/deleteReport/deleteReport.js @@ -9,7 +9,7 @@ const rawDataBuilder = build('rawData', { isRegulated: false, address1: fake((f) => f.address.streetAddress()), address2: fake((f) => f.address.secondaryAddress()), - address3: null, + address3: 'Third Address Line', town: fake((f) => f.address.city()), county: fake((f) => f.address.county()), postcode: fake((f) => f.address.zipCode('??# #??')), diff --git a/backend/server/test/unit/routes/reports/deleteReport/deleteReport.spec.js b/backend/server/test/unit/routes/reports/deleteReport/deleteReport.spec.js index 728bab04ac..2ad195d441 100644 --- a/backend/server/test/unit/routes/reports/deleteReport/deleteReport.spec.js +++ b/backend/server/test/unit/routes/reports/deleteReport/deleteReport.spec.js @@ -3,6 +3,7 @@ const expect = require('chai').expect; const sinon = require('sinon'); const httpMocks = require('node-mocks-http'); +const excelJS = require('exceljs'); const deleteReport = require('../../../../../routes/reports/deleteReport/report'); const models = require('../../../../../models'); @@ -11,7 +12,16 @@ const { rawDataBuilder } = require('../../../../factories/deleteReport/deleteRep describe('/server/routes/reports/deleteReport/report', () => { describe('deleteReport()', () => { + let req; + let res; + beforeEach(() => { + req = httpMocks.createRequest({ + method: 'GET', + url: '/api/report/deleteReport/report', + }); + res = httpMocks.createResponse(); + sinon.stub(models.pcodedata, 'getLinkedCssrRecordsFromPostcode').callsFake(async () => { return {}; }); @@ -24,11 +34,6 @@ describe('/server/routes/reports/deleteReport/report', () => { sinon.stub(models.establishment, 'generateDeleteReportData').callsFake(async () => { return [rawDataBuilder(), rawDataBuilder(), rawDataBuilder()]; }); - const req = httpMocks.createRequest({ - method: 'GET', - url: '/api/report/deleteReport/report', - }); - const res = httpMocks.createResponse(); await deleteReport.generateDeleteReport(req, res); @@ -37,5 +42,38 @@ describe('/server/routes/reports/deleteReport/report', () => { 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', ); }); + + describe('fillData', () => { + let workbook; + let mockWorksheet; + + beforeEach(() => { + workbook = new excelJS.Workbook(); + + mockWorksheet = workbook.addWorksheet('To be deleted', { views: [{ showGridLines: false }] }); + }); + + it('should fill next B cell with workplace name', async () => { + const workplaceData = rawDataBuilder(); + const expectedWorkplaceName = workplaceData.NameValue; + + deleteReport.fillData([workplaceData], {}, mockWorksheet); + + expect(mockWorksheet.getCell('B1').value).to.equal(expectedWorkplaceName); + }); + + it('should fill next C cell with concatenated address lines', async () => { + const workplaceData = rawDataBuilder(); + + deleteReport.fillData([workplaceData], {}, mockWorksheet); + + const addressCell = mockWorksheet.getCell('C1').value; + expect(addressCell).to.include(workplaceData.address1); + expect(addressCell).to.include(workplaceData.address2); + expect(addressCell).to.include(workplaceData.address3); + expect(addressCell).to.include(workplaceData.town); + expect(addressCell).to.include(workplaceData.county); + }); + }); }); }); diff --git a/backend/server/test/unit/utils/concatenateAddress.spec.js b/backend/server/test/unit/utils/concatenateAddress.spec.js new file mode 100644 index 0000000000..63a8895438 --- /dev/null +++ b/backend/server/test/unit/utils/concatenateAddress.spec.js @@ -0,0 +1,17 @@ +const expect = require('chai').expect; + +const concatenateAddress = require('../../../utils/concatenateAddress').concatenateAddress; + +describe('concatenateAddress', () => { + it('should only return address line 1 when only line 1 passed in', () => { + expect(concatenateAddress('Test Address Line 1')).to.equal('Test Address Line 1'); + }); + + it('should concatenate all lines with spaces between when all provided', () => { + expect(concatenateAddress('A', 'B', 'C', 'D', 'E')).to.equal('A B C D E'); + }); + + it('should concatenate with single spaces between when address lines 2 and 3 are missing but town and county exist', () => { + expect(concatenateAddress('A', undefined, undefined, 'D', 'E')).to.equal('A D E'); + }); +}); diff --git a/backend/server/utils/concatenateAddress.js b/backend/server/utils/concatenateAddress.js index d9c96ab0df..4a501972e1 100644 --- a/backend/server/utils/concatenateAddress.js +++ b/backend/server/utils/concatenateAddress.js @@ -1,10 +1,9 @@ -exports.concatenateAddress = function (addressLine1, addressLine2, townAndCity, county) { - - //Remove whitespaces and any non alphanumeric characters and then cast to upper case. +exports.concatenateAddress = function (addressLine1, addressLine2, addressLine3, townAndCity, county) { let concatAddress = ''; if (addressLine1) concatAddress += addressLine1; if (addressLine2) concatAddress += ' ' + addressLine2; + if (addressLine3) concatAddress += ' ' + addressLine3; if (townAndCity) concatAddress += ' ' + townAndCity; if (county) concatAddress += ' ' + county;