mapcomplete/test/scripts/GenerateCache.spec.ts

53 lines
235 KiB
TypeScript
Raw Normal View History

2022-03-24 03:30:05 +01:00
import {describe} from 'mocha'
import {expect} from 'chai'
import {Utils} from "../../Utils";
import {existsSync, mkdirSync, readFileSync, rmdirSync, unlinkSync} from "fs";
import ScriptUtils from "../../scripts/ScriptUtils";
import {main} from "../../scripts/generateCache";
function initDownloads(query: string){
const d = {"version":0.6,"generator":"Overpass API 0.7.57 93a4d346","osm3s":{"timestamp_osm_base":"2022-02-13T23:54:06Z","copyright":"The data included in this document is from www.openstreetmap.org. The data is made available under ODbL."},"elements":[{"type":"node","id":518224450,"lat":51.1548065,"lon":3.1880118,"tags":{"access":"yes","amenity":"parking","fee":"no","parking":"street_side"}},{"type":"node","id":665418924,"lat":51.1575547,"lon":3.20522,"tags":{"amenity":"parking"}},{"type":"node","id":1168727903,"lat":51.1299141,"lon":3.1776123,"tags":{"amenity":"drinking_water","mapillary":"https://www.mapillary.com/app/?lat=51.129853685131906&lng=3.177603984688602&z=17&pKey=SEyKzIMUeKssni1ZLVe-9A&focus=photo&dateTo=2017-04-02&dateFrom=2017-04-01&x=0.5168826751181941&y=0.6114877557873634&zoom=0"}},{"type":"node","id":1168728245,"lat":51.1290938,"lon":3.1767502,"tags":{"amenity":"drinking_water","mapillary":"https://www.mapillary.com/app/?lat=51.129104406662464&lng=3.176675795895676&z=17&pKey=vSP3D_hWv3XCBtH75GnYUQ&focus=photo&dateTo=2017-04-02&dateFrom=2017-04-01"}},{"type":"node","id":1725842653,"lat":51.153364,"lon":3.2352655,"tags":{"amenity":"bench"}},{"type":"node","id":1744641290,"lat":51.1389321,"lon":3.2385407,"tags":{"amenity":"bench","backrest":"yes","material":"wood"}},{"type":"node","id":1746891135,"lat":51.1598841,"lon":3.2361425,"tags":{"amenity":"bench"}},{"type":"node","id":1810326078,"lat":51.1550855,"lon":3.2349358,"tags":{"amenity":"bench"}},{"type":"node","id":1810326092,"lat":51.1552302,"lon":3.234968,"tags":{"amenity":"bench"}},{"type":"node","id":2325437742,"lat":51.1770052,"lon":3.1967794,"tags":{"board_type":"board","information":"board","name":"Tillegembos","tourism":"information"}},{"type":"node","id":2325437743,"lat":51.1787363,"lon":3.1949036,"tags":{"board_type":"board","information":"board","name":"Tillegembos","tourism":"information"}},{"type":"node","id":2325437813,"lat":51.1733102,"lon":3.1895672,"tags":{"amenity":"bench","backrest":"yes","material":"wood"}},{"type":"node","id":2325437839,"lat":51.1763436,"lon":3.1984985,"tags":{"amenity":"bench","backrest":"yes","material":"wood"}},{"type":"node","id":2325437848,"lat":51.1770966,"lon":3.1963507,"tags":{"amenity":"bench","backrest":"yes","material":"wood"}},{"type":"node","id":2325437862,"lat":51.1773439,"lon":3.1948779,"tags":{"amenity":"bench","backrest":"yes","material":"wood"}},{"type":"node","id":2325437867,"lat":51.1775994,"lon":3.1888088,"tags":{"amenity":"bench","backrest":"yes","material":"wood"}},{"type":"node","id":2325437873,"lat":51.1778384,"lon":3.1913802,"tags":{"amenity":"bench","backrest":"yes","material":"wood"}},{"type":"node","id":2732486257,"lat":51.129741,"lon":3.1907419,"tags":{"board_type":"nature","information":"board","name":"Doeveren","tourism":"information"}},{"type":"node","id":3774054068,"lat":51.1586662,"lon":3.2271102,"tags":{"amenity":"bench"}},{"type":"node","id":4769106605,"lat":51.138264,"lon":3.1798655,"tags":{"backrest":"yes","leisure":"picnic_table"}},{"type":"node","id":4912238707,"lat":51.1448634,"lon":3.2455986,"tags":{"access":"yes","amenity":"parking","fee":"no","name":"Oostkamp","parking":"Carpool"}},{"type":"node","id":5637212235,"lat":51.1305439,"lon":3.1866873,"tags":{"board_type":"nature","image":"https://i.imgur.com/HehOQL9.jpg","information":"board","name":"Welkom Doeveren","tourism":"information"}},{"type":"node","id":5637224573,"lat":51.1281084,"lon":3.1881726,"tags":{"board_type":"nature","information":"board","name":"Welkom Doeveren","tourism":"information"}},{"type":"node","id":5637230107,"lat":51.1280884,"lon":3.1889798,"tags":{"information":"board","tourism":"information"}},{"type":"node","id":5637743026,"lat":51.1295973,"lon":3.1751122,"tags":{"information":"board","name":"Doeveren Wandelroute","tourism":"information"}},{"type":"node","id":5716130103,"lat":51.1767183,"lon":3.1947867,"tags":{"amenity":"bench","backrest":"yes"}},{"type":"node","id":5745783208,"lat":51.1782581,"lon":3.2410111,"tags":{"amenity":"bench"}},{"type":"node","id":5745807545,"lat":51.1784037,"lon":3.2
2022-03-24 03:30:05 +01:00
Utils.injectJsonDownloadForTests(
"https://overpass-api.de/api/interpreter?data=%5Bout%3Ajson%5D%5Btimeout%3A60%5D%5Bbbox%3A51.124212757826875%2C3.1640625%2C51.17934297928927%2C3.251953125%5D%3B"+query , d
2022-03-24 03:30:05 +01:00
)
Utils.injectJsonDownloadForTests(
"https://overpass-api.de/api/interpreter?data=%5Bout%3Ajson%5D%5Btimeout%3A60%5D%5Bbbox%3A51.124212757826875%2C3.251953125%2C51.17934297928927%2C3.33984375%5D%3B"+query ,
{"version":0.6,"generator":"Overpass API 0.7.57 93a4d346","osm3s":{"timestamp_osm_base":"2022-02-14T00:02:14Z","copyright":"The data included in this document is from www.openstreetmap.org. The data is made available under ODbL."},"elements":[{"type":"node","id":668981602,"lat":51.1588243,"lon":3.2558654,"tags":{"amenity":"bench"}},{"type":"node","id":668981622,"lat":51.1565636,"lon":3.2549888,"tags":{"leisure":"bird_hide","operator":"Natuurpunt Vallei van de Zuidleie","shelter":"no"}},{"type":"node","id":1580339675,"lat":51.1395949,"lon":3.3332507,"tags":{"amenity":"parking"}},{"type":"node","id":1764571836,"lat":51.1701118,"lon":3.3363371,"tags":{"amenity":"parking"}},{"type":"node","id":2121652779,"lat":51.1268536,"lon":3.3239607,"tags":{"amenity":"parking"}},{"type":"node","id":2386053906,"lat":51.162161,"lon":3.263065,"tags":{"amenity":"toilets"}},{"type":"node","id":2978180520,"lat":51.1329149,"lon":3.3362322,"tags":{"amenity":"bench"}},{"type":"node","id":2978183271,"lat":51.1324243,"lon":3.3373735,"tags":{"amenity":"bench"}},{"type":"node","id":2978184471,"lat":51.1436385,"lon":3.2916539,"tags":{"amenity":"bench","backrest":"yes","check_date":"2021-02-26"}},{"type":"node","id":3925976407,"lat":51.1787486,"lon":3.2831866,"tags":{"leisure":"picnic_table"}},{"type":"node","id":5158056232,"lat":51.1592067,"lon":3.2567111,"tags":{"leisure":"bird_hide","operator":"Natuurpunt Vallei van de Zuidleie","shelter":"no"}},{"type":"node","id":5718776382,"lat":51.1609023,"lon":3.2582509,"tags":{"check_date":"2021-02-26","covered":"no","leisure":"picnic_table"}},{"type":"node","id":5718776383,"lat":51.1609488,"lon":3.2581877,"tags":{"check_date":"2021-02-26","covered":"no","leisure":"picnic_table"}},{"type":"node","id":5745727100,"lat":51.1594639,"lon":3.2604304,"tags":{"amenity":"bench"}},{"type":"node","id":5745739587,"lat":51.1580397,"lon":3.263101,"tags":{"check_date":"2021-02-26","leisure":"picnic_table"}},{"type":"node","id":5745739588,"lat":51.1580631,"lon":3.2630345,"tags":{"check_date":"2021-02-26","leisure":"picnic_table"}},{"type":"node","id":5961596093,"lat":51.1588103,"lon":3.2633933,"tags":{"leisure":"picnic_table"}},{"type":"node","id":5964032193,"lat":51.1514821,"lon":3.2723766,"tags":{"leisure":"picnic_table"}},{"type":"node","id":6034563379,"lat":51.1421689,"lon":3.3022271,"tags":{"leisure":"picnic_table"}},{"type":"node","id":6034564191,"lat":51.1722186,"lon":3.2823584,"tags":{"leisure":"picnic_table"}},{"type":"node","id":6034565298,"lat":51.1722796,"lon":3.282329,"tags":{"leisure":"picnic_table"}},{"type":"node","id":6145151111,"lat":51.1690435,"lon":3.3388676,"tags":{"amenity":"bench"}},{"type":"node","id":6145151112,"lat":51.1690023,"lon":3.3388636,"tags":{"amenity":"bench"}},{"type":"node","id":6216549651,"lat":51.1292813,"lon":3.332369,"tags":{"amenity":"bench"}},{"type":"node","id":6216549652,"lat":51.1292768,"lon":3.3324259,"tags":{"amenity":"bench"}},{"type":"node","id":7204447030,"lat":51.1791769,"lon":3.283116,"tags":{"board_type":"nature","information":"board","mapillary":"0BHVgU1XCyTMM9cjvidUqk","name":"De Assebroekse Meersen","tourism":"information"}},{"type":"node","id":7468175778,"lat":51.1344104,"lon":3.3348246,"tags":{"leisure":"picnic_table"}},{"type":"node","id":7602473480,"lat":51.1503874,"lon":3.2836867,"tags":{"leisure":"picnic_table"}},{"type":"node","id":7602473482,"lat":51.150244,"lon":3.2842925,"tags":{"board_type":"wildlife","information":"board","name":"Waterbeestjes","operator":"Natuurpunt Vallei van de Zuidleie","tourism":"information"}},{"type":"node","id":7602699080,"lat":51.1367031,"lon":3.3320712,"tags":{"amenity":"bench","backrest":"yes","material":"metal"}},{"type":"node","id":7680940369,"lat":51.1380074,"lon":3.3369928,"tags":{"amenity":"bench"}},{"type":"node","id":7726850522,"lat":51.1418585,"lon":3.3064234,"tags":{"image:0":"https://i.imgur.com/Bh6UjYy.jpg","information":"board","tourism":"information"}},{"type":"node","id":7727071212,"lat":51.1501173,"lon":3.2845352,"tags":{"board_type":"wildlife","image:0":"https://i.imgur.com/mFEQJWd.jpg","information":"boar
)
}
describe("GenerateCache", () => {
it("should generate a cached file for the Natuurpunt-theme", async () => {
if (existsSync("/tmp/np-cache")) {
ScriptUtils.readDirRecSync("/tmp/np-cache").forEach(p => unlinkSync(p))
rmdirSync("/tmp/np-cache")
}
mkdirSync("/tmp/np-cache")
initDownloads(
"(nwr%5B%22amenity%22%3D%22toilets%22%5D%3Bnwr%5B%22amenity%22%3D%22parking%22%5D%3Bnwr%5B%22amenity%22%3D%22bench%22%5D%3Bnwr%5B%22id%22%3D%22location_track%22%5D%3Bnwr%5B%22id%22%3D%22gps%22%5D%3Bnwr%5B%22information%22%3D%22board%22%5D%3Bnwr%5B%22leisure%22%3D%22picnic_table%22%5D%3Bnwr%5B%22man_made%22%3D%22watermill%22%5D%3Bnwr%5B%22user%3Ahome%22%3D%22yes%22%5D%3Bnwr%5B%22user%3Alocation%22%3D%22yes%22%5D%3Bnwr%5B%22leisure%22%3D%22nature_reserve%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22boundary%22%3D%22protected_area%22%5D%5B%22protect_class%22!%3D%2298%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22information%22%3D%22visitor_centre%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22information%22%3D%22office%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22route%22~%22%5E.*foot.*%24%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22route%22~%22%5E.*hiking.*%24%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22route%22~%22%5E.*bycicle.*%24%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22route%22~%22%5E.*horse.*%24%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22leisure%22%3D%22bird_hide%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22amenity%22%3D%22drinking_water%22%5D%5B%22access%22!%3D%22permissive%22%5D%5B%22access%22!%3D%22private%22%5D%3B)%3Bout%20body%3Bout%20meta%3B%3E%3Bout%20skel%20qt%3B"
2022-03-24 03:30:05 +01:00
);
await main([
"natuurpunt",
"12",
"/tmp/np-cache",
"51.15423567022531", "3.250579833984375", "51.162821593316934", "3.262810707092285",
"--generate-point-overview", "nature_reserve,visitor_information_centre"
])
await ScriptUtils.sleep(500)
2022-03-24 03:30:05 +01:00
const birdhides = JSON.parse(readFileSync("/tmp/np-cache/natuurpunt_birdhide_12_2085_1368.geojson", "UTF8"))
expect(birdhides.features.length).deep.equal(5)
expect(birdhides.features.some(f => f.properties.id === "node/5158056232"), "Didn't find birdhide node/5158056232 ").true
})
})