Files
watermaps/apps/api/tests/osm-marine-classification.test.mjs
T
2026-07-24 11:29:24 +02:00

41 lines
1.3 KiB
JavaScript

import { describe, expect, it } from "vitest";
import {
featureName,
isLockFeature,
sourceId
} from "../../../scripts/osm-marine-classification.mjs";
describe("OSM marine import classification", () => {
it.each([
{ lock: "yes" },
{ waterway: "lock_gate" },
{ waterway: "lock" },
{ natural: "water", water: "lock" },
{ obstacle: "lock" },
{ "seamark:type": "lock_basin" },
{ "seamark:type": "gate", "seamark:gate:category": "lock" }
])("recognizes a lock encoded as %o", (properties) => {
expect(isLockFeature(properties)).toBe(true);
});
it("does not classify an unrelated gate as a lock", () => {
expect(isLockFeature({ "seamark:type": "gate", "seamark:gate:category": "flood_barrage" })).toBe(false);
});
it("uses the canonical OSM id for converted area features", () => {
expect(
sourceId(
{ id: "a69307610", properties: { "@type": "way", "@id": 34653805 } },
1,
"nordrhein-westfalen-latest"
)
).toBe("w34653805");
});
it("prefers the lock name and falls back to the seamark name", () => {
expect(featureName({ lock_name: "Schleuse Test" })).toBe("Schleuse Test");
expect(featureName({ name: "Testkanal", lock_name: "Schleuse Test" })).toBe("Schleuse Test");
expect(featureName({ "seamark:name": "Test Lock" })).toBe("Test Lock");
});
});