From 0d3d3e486ce4000f41fde9a4490b97348579123f Mon Sep 17 00:00:00 2001 From: Tristan Slater <1631008+trslater@users.noreply.github.com> Date: Wed, 24 Apr 2024 09:59:47 -0700 Subject: [PATCH 1/2] Compare rounded lots vs. parcel size Avoids floating point error causing non-equality. --- ...pplication-submission-validator.service.ts | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/services/apps/alcs/src/portal/application-submission/application-submission-validator.service.ts b/services/apps/alcs/src/portal/application-submission/application-submission-validator.service.ts index b180f6708c..8b91a901b2 100644 --- a/services/apps/alcs/src/portal/application-submission/application-submission-validator.service.ts +++ b/services/apps/alcs/src/portal/application-submission/application-submission-validator.service.ts @@ -506,13 +506,21 @@ export class ApplicationSubmissionValidatorService { } } - const initialArea = parcels.reduce( - (totalSize, parcel) => totalSize + (parcel.mapAreaHectares ?? 0), - 0, + const initialArea = parseFloat( + parcels + .reduce( + (totalSize, parcel) => totalSize + (parcel.mapAreaHectares ?? 0), + 0, + ) + .toFixed(5), ); - const subdividedArea = applicationSubmission.subdProposedLots.reduce( - (totalSize, proposedLot) => totalSize + (proposedLot.size ?? 0), - 0, + const subdividedArea = parseFloat( + applicationSubmission.subdProposedLots + .reduce( + (totalSize, proposedLot) => totalSize + (proposedLot.size ?? 0), + 0, + ) + .toFixed(5), ); if (initialArea !== subdividedArea) { From 7ccc023d8c7a6c60d091a1f003847b107622e03d Mon Sep 17 00:00:00 2001 From: Tristan Slater <1631008+trslater@users.noreply.github.com> Date: Wed, 24 Apr 2024 10:17:25 -0700 Subject: [PATCH 2/2] Test floating new floating point comparison --- ...ation-submission-validator.service.spec.ts | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/services/apps/alcs/src/portal/application-submission/application-submission-validator.service.spec.ts b/services/apps/alcs/src/portal/application-submission/application-submission-validator.service.spec.ts index 68e3558018..dffa1ebb44 100644 --- a/services/apps/alcs/src/portal/application-submission/application-submission-validator.service.spec.ts +++ b/services/apps/alcs/src/portal/application-submission/application-submission-validator.service.spec.ts @@ -1261,7 +1261,7 @@ describe('ApplicationSubmissionValidatorService', () => { ).toBe(true); }); - it('should accept matching parcel sizes', async () => { + it('should accept exactly matching parcel sizes', async () => { const application = new ApplicationSubmission({ owners: [], typeCode: 'SUBD', @@ -1298,6 +1298,43 @@ describe('ApplicationSubmissionValidatorService', () => { ).toBe(false); }); + it('should accept matching parcel sizes up to 5 decimal places', async () => { + const application = new ApplicationSubmission({ + owners: [], + typeCode: 'SUBD', + subdProposedLots: [ + { + type: 'Lot', + size: 6.0, + planNumbers: null, + alrArea: null, + }, + { + type: 'Lot', + size: 6.000001, + planNumbers: null, + alrArea: null, + }, + ], + }); + + mockAppParcelService.fetchByApplicationFileId.mockResolvedValue([ + new ApplicationParcel({ + mapAreaHectares: 12, + owners: [], + }), + ]); + + const res = await service.validateSubmission(application); + + expect( + includesError( + res.errors, + new Error(`SUBD parcels area is different from proposed lot area`), + ), + ).toBe(false); + }); + it('should reject mismatched parcel sizes', async () => { const application = new ApplicationSubmission({ owners: [],