@@ -141,6 +141,8 @@ mod tests {
141141 ContentSecurityPolicyDirective ,
142142 } ,
143143 } ;
144+ use httpmock:: MockServer ;
145+ use serde_json:: json;
144146 use sqlx:: PgPool ;
145147 use uuid:: uuid;
146148
@@ -163,12 +165,29 @@ mod tests {
163165 }
164166
165167 /// Returns a `Config` configured for clone tests: a secrets encryption key is required
166- /// so the ephemeral-passphrase round-trip in `clone_user_data` can encrypt/decrypt.
167- fn clone_test_config ( ) -> anyhow:: Result < crate :: config:: Config > {
168+ /// so the ephemeral-passphrase round-trip in `clone_user_data` can encrypt/decrypt, and
169+ /// `retrack.host` is pointed at the supplied mock server so the export side's
170+ /// unconditional `GET /api/trackers` doesn't try to reach a real Retrack.
171+ ///
172+ /// The returned `MockServer` must be kept alive for the duration of the test; dropping
173+ /// it tears the listener down. We also pre-register a catch-all `GET /api/trackers`
174+ /// handler that returns an empty array, which is what every clone test in this file
175+ /// expects (none of them seed page/api trackers).
176+ fn clone_test_config ( ) -> anyhow:: Result < ( crate :: config:: Config , MockServer ) > {
168177 let mut config = mock_config ( ) ?;
169178 config. security . secrets_encryption_key =
170179 Some ( "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2" . to_string ( ) ) ;
171- Ok ( config)
180+
181+ let retrack_server = MockServer :: start ( ) ;
182+ retrack_server. mock ( |when, then| {
183+ when. method ( httpmock:: Method :: GET ) . path ( "/api/trackers" ) ;
184+ then. status ( 200 )
185+ . header ( "Content-Type" , "application/json" )
186+ . json_body ( json ! ( [ ] ) ) ;
187+ } ) ;
188+ config. retrack . host = url:: Url :: parse ( & retrack_server. base_url ( ) ) ?;
189+
190+ Ok ( ( config, retrack_server) )
172191 }
173192
174193 fn source_id ( ) -> uuid:: Uuid {
@@ -183,7 +202,8 @@ mod tests {
183202 /// touches no destination tables (the destination user is brand-new).
184203 #[ sqlx:: test]
185204 async fn clones_empty_user_with_zero_counts ( pool : PgPool ) -> anyhow:: Result < ( ) > {
186- let api = mock_api_with_config ( pool, clone_test_config ( ) ?) . await ?;
205+ let ( config, _retrack) = clone_test_config ( ) ?;
206+ let api = mock_api_with_config ( pool, config) . await ?;
187207 let source = mock_user_with_id ( source_id ( ) ) ?;
188208 let destination = mock_user_with_id ( destination_id ( ) ) ?;
189209 api. db . insert_user ( & source) . await ?;
@@ -207,7 +227,8 @@ mod tests {
207227 /// content of each entity is preserved verbatim on the destination side.
208228 #[ sqlx:: test]
209229 async fn clones_scripts_and_csps_under_new_ids ( pool : PgPool ) -> anyhow:: Result < ( ) > {
210- let api = mock_api_with_config ( pool, clone_test_config ( ) ?) . await ?;
230+ let ( config, _retrack) = clone_test_config ( ) ?;
231+ let api = mock_api_with_config ( pool, config) . await ?;
211232 let source = mock_user_with_id ( source_id ( ) ) ?;
212233 let destination = mock_user_with_id ( destination_id ( ) ) ?;
213234 api. db . insert_user ( & source) . await ?;
@@ -274,7 +295,8 @@ mod tests {
274295 async fn clones_secrets_via_ephemeral_passphrase_round_trip (
275296 pool : PgPool ,
276297 ) -> anyhow:: Result < ( ) > {
277- let api = mock_api_with_config ( pool, clone_test_config ( ) ?) . await ?;
298+ let ( config, _retrack) = clone_test_config ( ) ?;
299+ let api = mock_api_with_config ( pool, config) . await ?;
278300 let source = mock_user_with_id ( source_id ( ) ) ?;
279301 let destination = mock_user_with_id ( destination_id ( ) ) ?;
280302 api. db . insert_user ( & source) . await ?;
@@ -320,7 +342,8 @@ mod tests {
320342 async fn include_history_toggle_compiles_into_export_selection (
321343 pool : PgPool ,
322344 ) -> anyhow:: Result < ( ) > {
323- let api = mock_api_with_config ( pool, clone_test_config ( ) ?) . await ?;
345+ let ( config, _retrack) = clone_test_config ( ) ?;
346+ let api = mock_api_with_config ( pool, config) . await ?;
324347 let source = mock_user_with_id ( source_id ( ) ) ?;
325348 let destination = mock_user_with_id ( destination_id ( ) ) ?;
326349 api. db . insert_user ( & source) . await ?;
@@ -356,7 +379,8 @@ mod tests {
356379 } ,
357380 } ;
358381
359- let api = mock_api_with_config ( pool, clone_test_config ( ) ?) . await ?;
382+ let ( config, _retrack) = clone_test_config ( ) ?;
383+ let api = mock_api_with_config ( pool, config) . await ?;
360384 let source = mock_user_with_id ( source_id ( ) ) ?;
361385 api. db . insert_user ( & source) . await ?;
362386
0 commit comments