2023-07-15 18:55:03 +02:00
|
|
|
import { Utils } from "../../../src/Utils"
|
|
|
|
import { ChangesetHandler, ChangesetTag } from "../../../src/Logic/Osm/ChangesetHandler"
|
|
|
|
import { ImmutableStore, UIEventSource } from "../../../src/Logic/UIEventSource"
|
|
|
|
import { OsmConnection } from "../../../src/Logic/Osm/OsmConnection"
|
|
|
|
import { Changes } from "../../../src/Logic/Osm/Changes"
|
2023-02-03 04:48:32 +01:00
|
|
|
import { describe, expect, it } from "vitest"
|
2022-03-23 19:48:06 +01:00
|
|
|
|
2023-04-07 03:54:11 +02:00
|
|
|
function elstorage() {
|
2024-01-24 23:45:20 +01:00
|
|
|
return { addAlias: (_, __) => {} }
|
2023-04-07 03:54:11 +02:00
|
|
|
}
|
|
|
|
|
2022-03-23 19:48:06 +01:00
|
|
|
describe("ChangesetHanlder", () => {
|
|
|
|
describe("RewriteTagsOf", () => {
|
|
|
|
it("should insert new tags", () => {
|
|
|
|
const changesetHandler = new ChangesetHandler(
|
|
|
|
new UIEventSource<boolean>(true),
|
|
|
|
new OsmConnection({}),
|
2023-04-07 03:54:11 +02:00
|
|
|
elstorage(),
|
2023-05-17 13:16:43 +02:00
|
|
|
new Changes({
|
|
|
|
dryRun: new ImmutableStore(true),
|
2023-06-14 20:39:36 +02:00
|
|
|
osmConnection: new OsmConnection(),
|
2023-05-17 13:16:43 +02:00
|
|
|
})
|
2022-03-23 19:48:06 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const oldChangesetMeta = {
|
|
|
|
type: "changeset",
|
|
|
|
id: 118443748,
|
|
|
|
created_at: "2022-03-13T19:52:10Z",
|
|
|
|
closed_at: "2022-03-13T20:54:35Z",
|
|
|
|
open: false,
|
|
|
|
user: "Pieter Vander Vennet",
|
|
|
|
uid: 3818858,
|
|
|
|
minlat: 51.0361902,
|
|
|
|
minlon: 3.7092939,
|
|
|
|
maxlat: 51.0364194,
|
|
|
|
maxlon: 3.709952,
|
|
|
|
comments_count: 0,
|
|
|
|
changes_count: 3,
|
|
|
|
tags: {
|
|
|
|
answer: "5",
|
|
|
|
comment: "Adding data with #MapComplete for theme #toerisme_vlaanderen",
|
|
|
|
created_by: "MapComplete 0.16.6",
|
2023-08-23 18:33:30 +02:00
|
|
|
host: "https://mapcomplete.org/toerisme_vlaanderen.html",
|
2022-03-23 19:48:06 +01:00
|
|
|
imagery: "osm",
|
|
|
|
locale: "nl",
|
|
|
|
source: "survey",
|
|
|
|
"source:node/-1": "note/1234",
|
|
|
|
theme: "toerisme_vlaanderen",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
const rewritten = changesetHandler.RewriteTagsOf(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
key: "newTag",
|
|
|
|
value: "newValue",
|
|
|
|
aggregate: false,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
new Map<string, string>(),
|
|
|
|
oldChangesetMeta
|
|
|
|
)
|
|
|
|
const d = Utils.asDict(rewritten)
|
2023-02-03 04:48:32 +01:00
|
|
|
expect(d.size).toEqual(10)
|
|
|
|
expect(d.get("answer")).toEqual("5")
|
2023-04-07 03:54:11 +02:00
|
|
|
expect(d.get("comment")).toEqual(
|
|
|
|
"Adding data with #MapComplete for theme #toerisme_vlaanderen"
|
|
|
|
)
|
2023-02-03 04:48:32 +01:00
|
|
|
expect(d.get("created_by")).toEqual("MapComplete 0.16.6")
|
2023-08-23 18:33:30 +02:00
|
|
|
expect(d.get("host")).toEqual("https://mapcomplete.org/toerisme_vlaanderen.html")
|
2023-02-03 04:48:32 +01:00
|
|
|
expect(d.get("imagery")).toEqual("osm")
|
|
|
|
expect(d.get("source")).toEqual("survey")
|
|
|
|
expect(d.get("source:node/-1")).toEqual("note/1234")
|
|
|
|
expect(d.get("theme")).toEqual("toerisme_vlaanderen")
|
|
|
|
expect(d.get("newTag")).toEqual("newValue")
|
2022-03-23 19:48:06 +01:00
|
|
|
})
|
|
|
|
it("should aggregate numeric tags", () => {
|
|
|
|
const changesetHandler = new ChangesetHandler(
|
|
|
|
new UIEventSource<boolean>(true),
|
|
|
|
new OsmConnection({}),
|
2023-04-07 03:54:11 +02:00
|
|
|
elstorage(),
|
2023-05-17 13:16:43 +02:00
|
|
|
new Changes({
|
|
|
|
dryRun: new ImmutableStore(true),
|
2023-06-14 20:39:36 +02:00
|
|
|
osmConnection: new OsmConnection(),
|
2023-05-17 13:16:43 +02:00
|
|
|
})
|
2022-03-23 19:48:06 +01:00
|
|
|
)
|
|
|
|
const oldChangesetMeta = {
|
|
|
|
type: "changeset",
|
|
|
|
id: 118443748,
|
|
|
|
created_at: "2022-03-13T19:52:10Z",
|
|
|
|
closed_at: "2022-03-13T20:54:35Z",
|
|
|
|
open: false,
|
|
|
|
user: "Pieter Vander Vennet",
|
|
|
|
uid: 3818858,
|
|
|
|
minlat: 51.0361902,
|
|
|
|
minlon: 3.7092939,
|
|
|
|
maxlat: 51.0364194,
|
|
|
|
maxlon: 3.709952,
|
|
|
|
comments_count: 0,
|
|
|
|
changes_count: 3,
|
|
|
|
tags: {
|
|
|
|
answer: "5",
|
|
|
|
comment: "Adding data with #MapComplete for theme #toerisme_vlaanderen",
|
|
|
|
created_by: "MapComplete 0.16.6",
|
2023-08-23 18:33:30 +02:00
|
|
|
host: "https://mapcomplete.org/toerisme_vlaanderen.html",
|
2022-03-23 19:48:06 +01:00
|
|
|
imagery: "osm",
|
|
|
|
locale: "nl",
|
|
|
|
source: "survey",
|
|
|
|
"source:node/-1": "note/1234",
|
|
|
|
theme: "toerisme_vlaanderen",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
const rewritten = changesetHandler.RewriteTagsOf(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
key: "answer",
|
|
|
|
value: "37",
|
|
|
|
aggregate: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
new Map<string, string>(),
|
|
|
|
oldChangesetMeta
|
|
|
|
)
|
|
|
|
const d = Utils.asDict(rewritten)
|
|
|
|
|
2023-02-03 04:48:32 +01:00
|
|
|
expect(d.size).toEqual(9)
|
|
|
|
expect(d.get("answer")).toEqual("42")
|
2023-04-07 03:54:11 +02:00
|
|
|
expect(d.get("comment")).toEqual(
|
|
|
|
"Adding data with #MapComplete for theme #toerisme_vlaanderen"
|
|
|
|
)
|
2023-02-03 04:48:32 +01:00
|
|
|
expect(d.get("created_by")).toEqual("MapComplete 0.16.6")
|
2023-08-23 18:33:30 +02:00
|
|
|
expect(d.get("host")).toEqual("https://mapcomplete.org/toerisme_vlaanderen.html")
|
2023-02-03 04:48:32 +01:00
|
|
|
expect(d.get("imagery")).toEqual("osm")
|
|
|
|
expect(d.get("source")).toEqual("survey")
|
|
|
|
expect(d.get("source:node/-1")).toEqual("note/1234")
|
|
|
|
expect(d.get("theme")).toEqual("toerisme_vlaanderen")
|
2022-03-23 19:48:06 +01:00
|
|
|
})
|
|
|
|
it("should rewrite special reasons with the correct ID", () => {
|
|
|
|
const changesetHandler = new ChangesetHandler(
|
|
|
|
new UIEventSource<boolean>(true),
|
|
|
|
new OsmConnection({}),
|
2023-04-07 03:54:11 +02:00
|
|
|
elstorage(),
|
2023-05-17 13:16:43 +02:00
|
|
|
new Changes({
|
|
|
|
dryRun: new ImmutableStore(true),
|
2023-06-14 20:39:36 +02:00
|
|
|
osmConnection: new OsmConnection(),
|
2023-05-17 13:16:43 +02:00
|
|
|
})
|
2022-03-23 19:48:06 +01:00
|
|
|
)
|
|
|
|
const oldChangesetMeta = {
|
|
|
|
type: "changeset",
|
|
|
|
id: 118443748,
|
|
|
|
created_at: "2022-03-13T19:52:10Z",
|
|
|
|
closed_at: "2022-03-13T20:54:35Z",
|
|
|
|
open: false,
|
|
|
|
user: "Pieter Vander Vennet",
|
|
|
|
uid: 3818858,
|
|
|
|
minlat: 51.0361902,
|
|
|
|
minlon: 3.7092939,
|
|
|
|
maxlat: 51.0364194,
|
|
|
|
maxlon: 3.709952,
|
|
|
|
comments_count: 0,
|
|
|
|
changes_count: 3,
|
|
|
|
tags: {
|
|
|
|
answer: "5",
|
|
|
|
comment: "Adding data with #MapComplete for theme #toerisme_vlaanderen",
|
|
|
|
created_by: "MapComplete 0.16.6",
|
2023-08-23 18:33:30 +02:00
|
|
|
host: "https://mapcomplete.org/toerisme_vlaanderen.html",
|
2022-03-23 19:48:06 +01:00
|
|
|
imagery: "osm",
|
|
|
|
locale: "nl",
|
|
|
|
source: "survey",
|
|
|
|
"source:node/-1": "note/1234",
|
|
|
|
theme: "toerisme_vlaanderen",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
const rewritten = changesetHandler.RewriteTagsOf(
|
|
|
|
[],
|
|
|
|
new Map<string, string>([["node/-1", "node/42"]]),
|
|
|
|
oldChangesetMeta
|
|
|
|
)
|
|
|
|
const d = Utils.asDict(rewritten)
|
|
|
|
|
2023-02-03 04:48:32 +01:00
|
|
|
expect(d.size).toEqual(9)
|
|
|
|
expect(d.get("answer")).toEqual("5")
|
2023-04-07 03:54:11 +02:00
|
|
|
expect(d.get("comment")).toEqual(
|
|
|
|
"Adding data with #MapComplete for theme #toerisme_vlaanderen"
|
|
|
|
)
|
2023-02-03 04:48:32 +01:00
|
|
|
expect(d.get("created_by")).toEqual("MapComplete 0.16.6")
|
2023-08-23 18:33:30 +02:00
|
|
|
expect(d.get("host")).toEqual("https://mapcomplete.org/toerisme_vlaanderen.html")
|
2023-02-03 04:48:32 +01:00
|
|
|
expect(d.get("imagery")).toEqual("osm")
|
|
|
|
expect(d.get("source")).toEqual("survey")
|
|
|
|
expect(d.get("source:node/42")).toEqual("note/1234")
|
|
|
|
expect(d.get("theme")).toEqual("toerisme_vlaanderen")
|
2022-03-23 19:48:06 +01:00
|
|
|
})
|
|
|
|
})
|
2022-09-08 21:40:48 +02:00
|
|
|
|
2022-03-23 19:48:06 +01:00
|
|
|
describe("rewriteMetaTags", () => {
|
|
|
|
it("should rewrite special reasons with the correct ID", () => {
|
|
|
|
const extraMetaTags: ChangesetTag[] = [
|
|
|
|
{
|
|
|
|
key: "created_by",
|
|
|
|
value: "mapcomplete",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "source:node/-1",
|
|
|
|
value: "note/1234",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
const changes = new Map<string, string>([["node/-1", "node/42"]])
|
|
|
|
const hasSpecialMotivationChanges = ChangesetHandler.rewriteMetaTags(
|
|
|
|
extraMetaTags,
|
|
|
|
changes
|
|
|
|
)
|
2023-02-03 04:48:32 +01:00
|
|
|
// "Special rewrite did not trigger"
|
|
|
|
expect(hasSpecialMotivationChanges).toBe(true)
|
2022-03-23 19:48:06 +01:00
|
|
|
// Rewritten inline by rewriteMetaTags
|
2023-02-03 04:48:32 +01:00
|
|
|
expect(extraMetaTags[1].key).toEqual("source:node/42")
|
|
|
|
expect(extraMetaTags[1].value).toEqual("note/1234")
|
|
|
|
expect(extraMetaTags[0].key).toEqual("created_by")
|
|
|
|
expect(extraMetaTags[0].value).toEqual("mapcomplete")
|
2022-03-23 19:48:06 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|