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 bug if no cover found for specific cover name #120

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
10 changes: 8 additions & 2 deletions app/transformers/rural-payments/lms.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ export function transformLandParcelsEffectiveDates(parcelId, sheetId, parcels) {
}

export function transformLandCoversToArea(name, landCovers) {
const { area } = landCovers.find((landCover) => landCover.name === name)
return convertSquareMetersToHectares(area)
if (!landCovers || !Array.isArray(landCovers)) {
return 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 0 the correct value to be returning if we have no land covers rather than null?

}
const landCover = landCovers.find((landCover) => landCover?.name === name)
if (!landCover || !landCover.area) {
return 0
}
return convertSquareMetersToHectares(landCover.area)
}

export function transformLandParcels(landParcels) {
Expand Down
6 changes: 6 additions & 0 deletions test/unit/transformers/rural-payments-portal/lms.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ describe('LMS transformer', () => {
expect(transformLandCoversToArea(...input)).toEqual(output)
})

test('transformLandCoversToArea - no name found', () => {
const input = ['mockName', [{ name: 'no-name', area: 1000 }]]
const output = 0
expect(transformLandCoversToArea(...input)).toEqual(output)
})

test('transformLandParcels', () => {
const input = [
{
Expand Down