feat: add Docker/OpenTofu deployment and DE/NL routing
This commit is contained in:
@@ -1,12 +1,97 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { buildRoute } from "@watermaps/shared";
|
||||
import { createCache } from "../src/services/cache.js";
|
||||
import {
|
||||
FairwayService,
|
||||
fairwayRowsToGraph,
|
||||
localFairwaysToGraph,
|
||||
mergeConnectedFairwayGraphs,
|
||||
overpassToGraph
|
||||
} from "../src/services/fairways.js";
|
||||
|
||||
describe("fairway graph extraction", () => {
|
||||
it("builds a routable graph from the persistent local Geofabrik format", () => {
|
||||
const graph = localFairwaysToGraph(
|
||||
[
|
||||
{
|
||||
id: "local-1",
|
||||
bbox: [7.15, 53.62, 7.17, 53.71],
|
||||
tags: { route: "ferry", name: "Norddeich–Norderney" },
|
||||
coordinates: [
|
||||
[53.6234, 7.1559],
|
||||
[53.66, 7.16],
|
||||
[53.7023, 7.1658]
|
||||
]
|
||||
}
|
||||
],
|
||||
[7.0, 53.47, 7.32, 53.85],
|
||||
"germany-test.osm.pbf"
|
||||
);
|
||||
const route = buildRoute(
|
||||
{
|
||||
start: { lat: 53.6234, lon: 7.1559 },
|
||||
destination: { lat: 53.7023, lon: 7.1658 },
|
||||
vesselProfile: { draughtM: 1.4, safetyReserveM: 0.5, cruiseSpeedKn: 6 }
|
||||
},
|
||||
graph ?? undefined
|
||||
);
|
||||
|
||||
expect(route?.routingMode).toBe("fairway");
|
||||
expect(route?.dataSources).toContain("local-geofabrik-germany-test.osm.pbf");
|
||||
});
|
||||
|
||||
it("allows country-wide requests against the persistent local index", async () => {
|
||||
const temporaryDirectory = await mkdtemp(join(tmpdir(), "watermaps-local-span-"));
|
||||
const localDataPath = join(temporaryDirectory, "germany-netherlands-fairways.json");
|
||||
const request = {
|
||||
start: { lat: 52, lon: 4 },
|
||||
destination: { lat: 52, lon: 12 },
|
||||
vesselProfile: { draughtM: 1, safetyReserveM: 0.3 }
|
||||
};
|
||||
|
||||
try {
|
||||
await writeFile(
|
||||
localDataPath,
|
||||
JSON.stringify({
|
||||
version: 1,
|
||||
source: "germany+netherlands",
|
||||
ways: [
|
||||
{
|
||||
id: "country-wide-test",
|
||||
bbox: [4, 52, 12, 52],
|
||||
tags: { waterway: "canal", name: "Country-wide test fairway" },
|
||||
coordinates: [
|
||||
[52, 4],
|
||||
[52, 12]
|
||||
]
|
||||
}
|
||||
]
|
||||
})
|
||||
);
|
||||
|
||||
const service = new FairwayService({
|
||||
cache: createCache(),
|
||||
fetcher: fetch,
|
||||
liveEnabled: false,
|
||||
localDataPath
|
||||
});
|
||||
const graphs = await service.getGraphsForRoute(request);
|
||||
const route = buildRoute(request, graphs[0]);
|
||||
|
||||
expect(graphs).toHaveLength(1);
|
||||
expect(route?.routingMode).toBe("fairway");
|
||||
expect(route?.dataSources).toContain(
|
||||
"local-geofabrik-germany+netherlands"
|
||||
);
|
||||
await service.close();
|
||||
} finally {
|
||||
await rm(temporaryDirectory, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("builds a routable graph from PostGIS fairway rows", () => {
|
||||
const graph = fairwayRowsToGraph(
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user