mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
remove map tiler url from matrix wellknown
This commit is contained in:
@@ -20,10 +20,10 @@ struct MapTilerURLBuilderTests {
|
||||
var builder: MapTilerURLBuilderProtocol
|
||||
|
||||
init() {
|
||||
builder = MapTilerSettings.configuration(.init(baseURL: Self.baseURL,
|
||||
apiKey: Self.apiKey,
|
||||
lightStyleID: Self.lightStyleID,
|
||||
darkStyleID: Self.darkStyleID))
|
||||
builder = MapTilerConfiguration(baseURL: Self.baseURL,
|
||||
apiKey: Self.apiKey,
|
||||
lightStyleID: Self.lightStyleID,
|
||||
darkStyleID: Self.darkStyleID)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -59,10 +59,10 @@ struct MapTilerURLBuilderTests {
|
||||
|
||||
@Test
|
||||
mutating func nilAPIKey() {
|
||||
let configuration = MapTilerSettings.configuration(.init(baseURL: Self.baseURL,
|
||||
apiKey: nil,
|
||||
lightStyleID: Self.lightStyleID,
|
||||
darkStyleID: Self.darkStyleID))
|
||||
let configuration = MapTilerConfiguration(baseURL: Self.baseURL,
|
||||
apiKey: nil,
|
||||
lightStyleID: Self.lightStyleID,
|
||||
darkStyleID: Self.darkStyleID)
|
||||
#expect(!configuration.isEnabled)
|
||||
|
||||
builder = configuration
|
||||
@@ -78,65 +78,28 @@ struct MapTilerURLBuilderTests {
|
||||
#expect(dynamicMapURL == nil)
|
||||
}
|
||||
|
||||
// MARK: - Override URL
|
||||
|
||||
@Test
|
||||
mutating func overrideInteractiveMap() {
|
||||
let overrideURL: URL = "https://maps.example.com/maps/streets-v2/style.json?key=server_key"
|
||||
let configuration = MapTilerSettings.url(overrideURL)
|
||||
mutating func emptyAPIKey() {
|
||||
// An empty key means the server proxies it for us, so location sharing remains enabled
|
||||
// but the URLs mustn't contain a key.
|
||||
let configuration = MapTilerConfiguration(baseURL: Self.baseURL,
|
||||
apiKey: "",
|
||||
lightStyleID: Self.lightStyleID,
|
||||
darkStyleID: Self.darkStyleID)
|
||||
#expect(configuration.isEnabled)
|
||||
|
||||
builder = configuration
|
||||
|
||||
// The override is returned as-is for the interactive map, ignoring light/dark.
|
||||
#expect(builder.interactiveMapURL(for: .light) == overrideURL)
|
||||
#expect(builder.interactiveMapURL(for: .dark) == overrideURL)
|
||||
}
|
||||
|
||||
@Test
|
||||
mutating func overrideStaticMapPreservesQueryItems() {
|
||||
// The override includes an embedded API key as a query item — it must be preserved
|
||||
// when deriving the static map URL.
|
||||
let overrideURL: URL = "https://maps.example.com/maps/streets-v2/style.json?key=server_key"
|
||||
builder = MapTilerSettings.url(overrideURL)
|
||||
let staticMapURL = builder.staticMapTileImageURL(for: .dark,
|
||||
coordinates: .init(latitude: 1, longitude: 2),
|
||||
zoomLevel: 5,
|
||||
size: .init(width: 300, height: 200),
|
||||
attribution: .topLeft)
|
||||
let expectedStaticMapURL: URL = "http://www.foo.com/dea61faf-292b-4774-9660-58fcef89a7f3/static/2.000000,1.000000,5.000000/300x200@2x.png?attribution=topleft"
|
||||
#expect(staticMapURL == expectedStaticMapURL)
|
||||
|
||||
let url = builder.staticMapTileImageURL(for: .light,
|
||||
coordinates: .init(latitude: 1, longitude: 2),
|
||||
zoomLevel: 5,
|
||||
size: .init(width: 300, height: 200),
|
||||
attribution: .topLeft)
|
||||
|
||||
let expectedURL: URL = "https://maps.example.com/maps/streets-v2/static/2.000000,1.000000,5.000000/300x200@2x.png?key=server_key&attribution=topleft"
|
||||
#expect(url == expectedURL)
|
||||
}
|
||||
|
||||
@Test
|
||||
mutating func overrideStaticMapWithoutQueryItems() {
|
||||
// An override without a key (e.g. self-hosted server proxying the key) still works.
|
||||
let overrideURL: URL = "https://maps.example.com/maps/streets-v2/style.json"
|
||||
builder = MapTilerSettings.url(overrideURL)
|
||||
|
||||
let url = builder.staticMapTileImageURL(for: .dark,
|
||||
coordinates: .init(latitude: 1, longitude: 2),
|
||||
zoomLevel: 5,
|
||||
size: .init(width: 300, height: 200),
|
||||
attribution: .hidden)
|
||||
|
||||
let expectedURL: URL = "https://maps.example.com/maps/streets-v2/static/2.000000,1.000000,5.000000/300x200@2x.png?attribution=false"
|
||||
#expect(url == expectedURL)
|
||||
}
|
||||
|
||||
@Test
|
||||
mutating func overrideMissingStyleJSONFails() {
|
||||
// If the override URL doesn't end in /style.json we can't derive a static URL.
|
||||
let overrideURL: URL = "https://maps.example.com/maps/streets-v2/"
|
||||
builder = MapTilerSettings.url(overrideURL)
|
||||
|
||||
let url = builder.staticMapTileImageURL(for: .light,
|
||||
coordinates: .init(latitude: 1, longitude: 2),
|
||||
zoomLevel: 5,
|
||||
size: .init(width: 300, height: 200),
|
||||
attribution: .topLeft)
|
||||
#expect(url == nil)
|
||||
let dynamicMapURL = builder.interactiveMapURL(for: .light)
|
||||
let expectedDynamicMapURL: URL = "http://www.foo.com/9bc819c8-e627-474a-a348-ec144fe3d810/style.json"
|
||||
#expect(dynamicMapURL == expectedDynamicMapURL)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user