Skip to content

Commit

Permalink
Merge pull request #1621 from bcgov/hotfix/ALCS-1855
Browse files Browse the repository at this point in the history
Compare rounded lot vs. parcel size to avoid floating non-equality
  • Loading branch information
trslater authored Apr 24, 2024
2 parents 04aedc2 + 7ccc023 commit d5d0d3f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d5d0d3f

Please sign in to comment.