From 6f86ae50fd79df60b16d6a489910e786aecbe299 Mon Sep 17 00:00:00 2001 From: Sven Verweij <37927107+SvenVw@users.noreply.github.com> Date: Tue, 29 Jul 2025 12:06:44 +0200 Subject: [PATCH 1/3] test: add unit test to confirm #205 --- .../nl/2025/dierlijke-mest-gebruiksnorm.test.ts | 15 +++++++++++++++ .../norms/nl/2025/stikstofgebruiksnorm.test.ts | 6 ++++++ 2 files changed, 21 insertions(+) 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..210edb5a7 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 responce (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/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) From b6bf9b7d93485fe754eb684bd85da5bf1fa29728 Mon Sep 17 00:00:00 2001 From: Sven Verweij <37927107+SvenVw@users.noreply.github.com> Date: Tue, 29 Jul 2025 12:25:24 +0200 Subject: [PATCH 2/3] fix: response can contain single array for some locations --- .../src/norms/nl/2025/dierlijke-mest-gebruiksnorm.ts | 8 +++++--- fdm-calculator/src/norms/nl/2025/stikstofgebruiksnorm.ts | 9 ++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) 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.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) { From e12f2af58a50d2ad42bd975441fb0e8ff41f292b Mon Sep 17 00:00:00 2001 From: Sven Verweij <37927107+SvenVw@users.noreply.github.com> Date: Tue, 29 Jul 2025 13:03:38 +0200 Subject: [PATCH 3/3] fix: typo --- .../src/norms/nl/2025/dierlijke-mest-gebruiksnorm.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 210edb5a7..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 @@ -80,7 +80,7 @@ describe("getNL2025DierlijkeMestGebruiksNorm", () => { ) }) - it("should return the default norm value for derogation outside Grondwaterbeschermingsgebied and inside NV-gebied, but with single array responce (see #205)", async () => { + 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: {