Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,19 @@ describe("getNL2025DierlijkeMestGebruiksNorm", () => {
"Derogatie - Grondwaterbeschermingsgebied",
)
})

it("should return the default norm value for derogation outside Grondwaterbeschermingsgebied and inside NV-gebied, but with single array response (see #205)", async () => {
const mockInput: NL2025NormsInput = {
farm: { is_derogatie_bedrijf: true },
field: {
b_id: "1",
b_centroid: [5.058131582583726, 52.50733333508596],
},
cultivations: [],
soilAnalysis: { a_p_cc: 0, a_p_al: 0 },
}
const result = await getNL2025DierlijkeMestGebruiksNorm(mockInput)
expect(result.normValue).toBe(190)
expect(result.normSource).toBe("Derogatie - NV Gebied")
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ export async function isFieldInGWGBGebied(
throw new Error(`Failed to fetch ${url}: ${response.statusText}`)
}
const json = await response.json()
const feature = json[0][0]
if (feature) {
return true
if (json.length > 0) { // Check if not single array response
const feature = json[0][0]
if (feature) {
return true
}
}
return false
} catch (err) {
Expand Down
6 changes: 6 additions & 0 deletions fdm-calculator/src/norms/nl/2025/stikstofgebruiksnorm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ describe("stikstofgebruiksnorm helpers", () => {
expect(result).toBe(false)
})

it("should correctly identify a field not in an NV Gebied, but with single array response (see #205)", async () => {
const centroidOutsideNV = [5.5527872994244785, 52.92595151470198] // Known point outside NV Gebied
const result = await isFieldInNVGebied(centroidOutsideNV)
expect(result).toBe(false)
})

it("should correctly identify the region for a field", async () => {
const centroidInKlei = [5.64188724, 51.977587] // Known point in Klei
const region = await getRegion(centroidInKlei)
Expand Down
9 changes: 6 additions & 3 deletions fdm-calculator/src/norms/nl/2025/stikstofgebruiksnorm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ export async function isFieldInNVGebied(
throw new Error(`Failed to fetch ${url}: ${response.statusText}`)
}
const json = await response.json()
const feature = json[0][0]
if (feature) {
return true
if (json.length > 0) {
// Check if not single array response
const feature = json[0][0]
if (feature) {
return true
}
}
return false
} catch (err) {
Expand Down