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

Fix/1498 address in deletion report #6348

Merged
merged 3 commits into from
Sep 10, 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
3 changes: 2 additions & 1 deletion backend/server/routes/reports/deleteReport/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -161,4 +161,5 @@ const generateDeleteReport = async (req, res) => {

module.exports = router;
module.exports.generateDeleteReport = generateDeleteReport;
module.exports.fillData = fillData;
module.exports.monthsWithoutUpdate = monthsWithoutUpdate;
2 changes: 1 addition & 1 deletion backend/server/test/factories/deleteReport/deleteReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('??# #??')),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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 {};
});
Expand All @@ -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);

Expand All @@ -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);
});
});
});
});
17 changes: 17 additions & 0 deletions backend/server/test/unit/utils/concatenateAddress.spec.js
Original file line number Diff line number Diff line change
@@ -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');
});
});
5 changes: 2 additions & 3 deletions backend/server/utils/concatenateAddress.js
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Loading