@@ -131,6 +131,7 @@ public async Task should_fall_back_to_leaflet_system_config_when_override_disabl
131131 public async Task should_fall_back_to_mapbox_system_config_when_website_mode_is_mapbox ( )
132132 {
133133 MappingConfig . WebsiteMapMode = MappingConfig . MapboxMapProvider ;
134+ MappingConfig . WebsiteOSMKey = "pk.system-token" ;
134135
135136 _departmentSettingsRepository
136137 . Setup ( x => x . GetDepartmentSettingByIdTypeAsync ( 7 , DepartmentSettingTypes . MappingUseMapboxOverride ) )
@@ -140,7 +141,7 @@ public async Task should_fall_back_to_mapbox_system_config_when_website_mode_is_
140141
141142 result . IsDepartmentOverride . Should ( ) . BeFalse ( ) ;
142143 result . MapProvider . Should ( ) . Be ( MappingConfig . MapboxMapProvider ) ;
143- result . AccessToken . Should ( ) . Be ( "system-token" ) ;
144+ result . AccessToken . Should ( ) . Be ( "pk. system-token" ) ;
144145 result . StyleUrl . Should ( ) . Be ( "mapbox://styles/resgrid/abc123" ) ;
145146 }
146147
@@ -184,6 +185,7 @@ public async Task should_use_configured_mapbox_tile_url_when_style_url_is_missin
184185 {
185186 MappingConfig . WebsiteMapMode = MappingConfig . MapboxMapProvider ;
186187 MappingConfig . MapBoxStyleUrl = string . Empty ;
188+ MappingConfig . WebsiteOSMKey = "pk.system-token" ;
187189
188190 _departmentSettingsRepository
189191 . Setup ( x => x . GetDepartmentSettingByIdTypeAsync ( 7 , DepartmentSettingTypes . MappingUseMapboxOverride ) )
@@ -192,15 +194,16 @@ public async Task should_use_configured_mapbox_tile_url_when_style_url_is_missin
192194 var result = await _service . GetMapConfigForDepartmentAsync ( 7 , InfoConfig . WebsiteKey ) ;
193195
194196 result . MapProvider . Should ( ) . Be ( MappingConfig . MapboxMapProvider ) ;
195- result . TileUrl . Should ( ) . Be ( "https://api.mapbox.com/styles/v1/resgrid/abc123/tiles/256/{z}/{x}/{y}?access_token=system-token" ) ;
197+ result . TileUrl . Should ( ) . Be ( "https://api.mapbox.com/styles/v1/resgrid/abc123/tiles/256/{z}/{x}/{y}?access_token=pk. system-token" ) ;
196198 result . StyleUrl . Should ( ) . BeEmpty ( ) ;
197- result . AccessToken . Should ( ) . Be ( "system-token" ) ;
199+ result . AccessToken . Should ( ) . Be ( "pk. system-token" ) ;
198200 }
199201
200202 [ Test ]
201203 public async Task should_fall_back_to_system_config_when_override_is_incomplete ( )
202204 {
203205 MappingConfig . WebsiteMapMode = MappingConfig . MapboxMapProvider ;
206+ MappingConfig . WebsiteOSMKey = "pk.system-token" ;
204207
205208 _departmentSettingsRepository
206209 . Setup ( x => x . GetDepartmentSettingByIdTypeAsync ( 7 , DepartmentSettingTypes . MappingUseMapboxOverride ) )
@@ -215,8 +218,48 @@ public async Task should_fall_back_to_system_config_when_override_is_incomplete(
215218 var result = await _service . GetMapConfigForDepartmentAsync ( 7 , InfoConfig . WebsiteKey ) ;
216219
217220 result . IsDepartmentOverride . Should ( ) . BeFalse ( ) ;
218- result . AccessToken . Should ( ) . Be ( "system-token" ) ;
221+ result . AccessToken . Should ( ) . Be ( "pk. system-token" ) ;
219222 result . StyleUrl . Should ( ) . Be ( "mapbox://styles/resgrid/abc123" ) ;
220223 }
224+
225+ [ Test ]
226+ public async Task should_fall_back_to_leaflet_when_website_mapbox_access_token_is_private ( )
227+ {
228+ MappingConfig . WebsiteMapMode = MappingConfig . MapboxMapProvider ;
229+ MappingConfig . WebsiteMapboxAccessToken = "sk.website-secret" ;
230+ MappingConfig . WebsiteOSMKey = string . Empty ;
231+
232+ _departmentSettingsRepository
233+ . Setup ( x => x . GetDepartmentSettingByIdTypeAsync ( 7 , DepartmentSettingTypes . MappingUseMapboxOverride ) )
234+ . ReturnsAsync ( new DepartmentSetting { DepartmentId = 7 , Setting = "false" , SettingType = ( int ) DepartmentSettingTypes . MappingUseMapboxOverride } ) ;
235+
236+ var result = await _service . GetMapConfigForDepartmentAsync ( 7 , InfoConfig . WebsiteKey ) ;
237+
238+ result . MapProvider . Should ( ) . Be ( MappingConfig . LeafletMapProvider ) ;
239+ result . AccessToken . Should ( ) . BeEmpty ( ) ;
240+ result . StyleUrl . Should ( ) . BeEmpty ( ) ;
241+ result . TileUrl . Should ( ) . NotContain ( "sk.website-secret" ) ;
242+ }
243+
244+ [ Test ]
245+ public async Task should_ignore_department_override_when_mapbox_access_token_is_private ( )
246+ {
247+ _departmentSettingsRepository
248+ . Setup ( x => x . GetDepartmentSettingByIdTypeAsync ( 7 , DepartmentSettingTypes . MappingUseMapboxOverride ) )
249+ . ReturnsAsync ( new DepartmentSetting { DepartmentId = 7 , Setting = "true" , SettingType = ( int ) DepartmentSettingTypes . MappingUseMapboxOverride } ) ;
250+ _departmentSettingsRepository
251+ . Setup ( x => x . GetDepartmentSettingByIdTypeAsync ( 7 , DepartmentSettingTypes . MappingMapboxStyleUrl ) )
252+ . ReturnsAsync ( new DepartmentSetting { DepartmentId = 7 , Setting = "mapbox://styles/department/customstyle" , SettingType = ( int ) DepartmentSettingTypes . MappingMapboxStyleUrl } ) ;
253+ _departmentSettingsRepository
254+ . Setup ( x => x . GetDepartmentSettingByIdTypeAsync ( 7 , DepartmentSettingTypes . MappingMapboxAccessToken ) )
255+ . ReturnsAsync ( new DepartmentSetting { DepartmentId = 7 , Setting = "sk.department-secret" , SettingType = ( int ) DepartmentSettingTypes . MappingMapboxAccessToken } ) ;
256+
257+ var result = await _service . GetMapConfigForDepartmentAsync ( 7 , InfoConfig . WebsiteKey ) ;
258+
259+ result . IsDepartmentOverride . Should ( ) . BeFalse ( ) ;
260+ result . MapProvider . Should ( ) . Be ( MappingConfig . LeafletMapProvider ) ;
261+ result . AccessToken . Should ( ) . BeEmpty ( ) ;
262+ result . TileUrl . Should ( ) . NotContain ( "sk.department-secret" ) ;
263+ }
221264 }
222265}
0 commit comments