diff --git a/fdm-calculator/src/norms/nl/2025/dierlijke-mest-gebruiksnorm.test.ts b/fdm-calculator/src/norms/nl/2025/dierlijke-mest-gebruiksnorm.test.ts index bd6ac85e5..4021582b5 100644 --- a/fdm-calculator/src/norms/nl/2025/dierlijke-mest-gebruiksnorm.test.ts +++ b/fdm-calculator/src/norms/nl/2025/dierlijke-mest-gebruiksnorm.test.ts @@ -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") + }) }) diff --git a/fdm-calculator/src/norms/nl/2025/dierlijke-mest-gebruiksnorm.ts b/fdm-calculator/src/norms/nl/2025/dierlijke-mest-gebruiksnorm.ts index 68405b64d..9c91c5cbc 100644 --- a/fdm-calculator/src/norms/nl/2025/dierlijke-mest-gebruiksnorm.ts +++ b/fdm-calculator/src/norms/nl/2025/dierlijke-mest-gebruiksnorm.ts @@ -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) { diff --git a/fdm-calculator/src/norms/nl/2025/stikstofgebruiksnorm.test.ts b/fdm-calculator/src/norms/nl/2025/stikstofgebruiksnorm.test.ts index d14324da7..b99c33a56 100644 --- a/fdm-calculator/src/norms/nl/2025/stikstofgebruiksnorm.test.ts +++ b/fdm-calculator/src/norms/nl/2025/stikstofgebruiksnorm.test.ts @@ -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) diff --git a/fdm-calculator/src/norms/nl/2025/stikstofgebruiksnorm.ts b/fdm-calculator/src/norms/nl/2025/stikstofgebruiksnorm.ts index cd4233103..29eede598 100644 --- a/fdm-calculator/src/norms/nl/2025/stikstofgebruiksnorm.ts +++ b/fdm-calculator/src/norms/nl/2025/stikstofgebruiksnorm.ts @@ -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) {