feat(train): the instance names its map source (ADR 0030, D11, D22)

Train's first endpoint of its own, map.source, names the map workouts
are drawn on, for people signed in only, as a provider's key may be in
its style's address: OpenFreeMap's Liberty style where the operator sets
nothing, else MAP_STYLE_URL (HTTPS only) with MAP_SOURCE_NAME,
MAP_ATTRIBUTION and MAP_ABOUT_URL. A model without a table: no
migration. D22 is recorded in ADR 0030.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
Tizian 「ティツィアーン」 2026-10-28 13:42:28 +01:00
commit dd778cb2cd
Signed by: raisondetredev
GPG key ID: 07F6FCF405488B64

View file

@ -0,0 +1,68 @@
import 'package:halkyon_train_server/src/map/map_source_config.dart';
import 'package:test/test.dart';
/// The instance's map source as its operator sets it (ADR 0030, D11, D22).
void main() {
test('without a setting it is OpenFreeMap, named, with its attribution', () {
final source = mapSourceFrom(const {});
expect(source.name, 'OpenFreeMap');
expect(source.styleUrl, 'https://tiles.openfreemap.org/styles/liberty');
expect(source.attribution, contains('OpenStreetMap'));
expect(source.aboutUrl, 'https://openfreemap.org');
});
test("an operator's provider is named as they set it", () {
final source = mapSourceFrom(const {
'MAP_STYLE_URL':
'https://api.maptiler.com/maps/outdoor-v2/style.json?key=k',
'MAP_SOURCE_NAME': 'MapTiler',
'MAP_ATTRIBUTION': '© MapTiler © OpenStreetMap contributors',
'MAP_ABOUT_URL': 'https://www.maptiler.com/privacy-policy/',
});
expect(source.name, 'MapTiler');
expect(
source.styleUrl,
'https://api.maptiler.com/maps/outdoor-v2/style.json?key=k',
);
expect(source.attribution, '© MapTiler © OpenStreetMap contributors');
expect(source.aboutUrl, 'https://www.maptiler.com/privacy-policy/');
});
test('a provider without a name is named by its host, and credits '
'OpenStreetMap', () {
final source = mapSourceFrom(const {
'MAP_STYLE_URL': 'https://maps.example.org/style.json',
});
expect(source.name, 'maps.example.org');
expect(source.attribution, '© OpenStreetMap contributors');
expect(source.aboutUrl, isNull);
});
test("a style that isn't HTTPS, or isn't an address, is never used: the "
'map stays OpenFreeMap', () {
for (final url in [
'http://maps.example.org/style.json',
'maps.example.org/style.json',
'https://',
' ',
]) {
expect(
mapSourceFrom({'MAP_STYLE_URL': url}).name,
'OpenFreeMap',
reason: url,
);
}
});
test("an about page that isn't HTTPS is left out", () {
final source = mapSourceFrom(const {
'MAP_STYLE_URL': 'https://maps.example.org/style.json',
'MAP_ABOUT_URL': 'javascript:alert(1)',
});
expect(source.aboutUrl, isNull);
});
}