@@ -21,13 +21,22 @@ pub struct EntsoePriceSource {
2121}
2222
2323impl EntsoePriceSource {
24- pub fn new ( api_key : & str ) -> Self {
24+ /// Creates a new instance of the ENTSO-E price source, with a custom base URL.
25+ /// See [EntsoePriceSource::new] to use the default base URL.
26+ // Useful for integration testing.
27+ pub fn new_with_base_url ( api_key : & str , base_url : & str ) -> Self {
2528 EntsoePriceSource {
2629 api_key : api_key. into ( ) ,
27- base_url : "https://web-api.tp.entsoe.eu/" . to_string ( ) ,
30+ base_url : base_url . into ( ) ,
2831 }
2932 }
3033
34+ /// Creates a new instance of the ENTSO-E price source.
35+ /// See [EntsoePriceSource::new_with_base_url] to use a custom base URL.
36+ pub fn new ( api_key : & str ) -> Self {
37+ EntsoePriceSource :: new_with_base_url ( api_key, "https://web-api.tp.entsoe.eu/" )
38+ }
39+
3140 /// Gets the API URL used to fetch day-ahead price data from ENTSO-E.
3241 // https://documenter.getpostman.com/view/7009892/2s93JtP3F6#3b383df0-ada2-49fe-9a50-98b1bb201c6b
3342 // Beware of awkward time format used by ENTOS-E.
@@ -237,15 +246,12 @@ mod tests {
237246
238247 #[ gtest]
239248 fn test_get_api_url_custom_base ( ) {
240- let url = EntsoePriceSource {
241- api_key : "fake-api-key" . to_string ( ) ,
242- base_url : "https://example.com/" . to_string ( ) ,
243- }
244- . get_api_url (
245- DeliveryArea :: NO1 ,
246- Time :: date ( 2025 , 12 , 29 ) . clock ( 00 , 00 , 00 ) ,
247- Time :: date ( 2025 , 12 , 30 ) . clock ( 00 , 00 , 00 ) ,
248- ) ;
249+ let url = EntsoePriceSource :: new_with_base_url ( "fake-api-key" , "https://example.com/" )
250+ . get_api_url (
251+ DeliveryArea :: NO1 ,
252+ Time :: date ( 2025 , 12 , 29 ) . clock ( 00 , 00 , 00 ) ,
253+ Time :: date ( 2025 , 12 , 30 ) . clock ( 00 , 00 , 00 ) ,
254+ ) ;
249255 expect_that ! (
250256 url,
251257 eq(
0 commit comments