diff --git a/editoast/src/views/train_schedule.rs b/editoast/src/views/train_schedule.rs index 732d51257e6..fb6370d1e26 100644 --- a/editoast/src/views/train_schedule.rs +++ b/editoast/src/views/train_schedule.rs @@ -1045,15 +1045,77 @@ mod tests { // Ignore the rest of the payload } + fn mocked_core_for_project_path(train_id: i64) -> MockingClient { + let mut core = MockingClient::new(); + core.stub("/v2/pathfinding/blocks") + .method(reqwest::Method::POST) + .response(StatusCode::OK) + .json(json!({ + "blocks":[], + "routes": [], + "track_section_ranges": [], + "path_item_positions": [0,1,2,3], + "length": 0, + "status": "success" + })) + .finish(); + core.stub("/v2/standalone_simulation") + .method(reqwest::Method::POST) + .response(StatusCode::OK) + .json(json!({ + "status": "success", + "base": { + "positions": [], + "times": [], + "speeds": [], + "energy_consumption": 0.0, + "path_item_times": [0, 1000, 2000, 3000] + }, + "provisional": { + "positions": [], + "times": [], + "speeds": [], + "energy_consumption": 0.0, + "path_item_times": [0, 1000, 2000, 3000] + }, + "final_output": { + "positions": [0], + "times": [0], + "speeds": [], + "energy_consumption": 0.0, + "path_item_times": [0, 1000, 2000, 3000], + "signal_critical_positions": [], + "zone_updates": [], + "spacing_requirements": [], + "routing_requirements": [] + }, + "mrsp": { + "boundaries": [], + "values": [] + }, + "electrical_profiles": { + "boundaries": [], + "values": [] + } + })) + .finish(); + core.stub("/v2/signal_projection") + .method(reqwest::Method::POST) + .response(StatusCode::OK) + .json(json!({ + "signal_updates": {train_id.to_string(): [] }, + })) + .finish(); + core + } + + + #[rstest] async fn train_schedule_project_path() { // SETUP let db_pool = DbConnectionPoolV2::for_tests(); - let core = mocked_core_pathfinding_and_sim(); - let app = TestAppBuilder::new() - .db_pool(db_pool.clone()) - .core_client(core.into()) - .build(); + let small_infra = create_small_infra(&mut db_pool.get_ok()).await; let rolling_stock = create_fast_rolling_stock(&mut db_pool.get_ok(), "simulation_rolling_stock").await; @@ -1082,11 +1144,20 @@ mod tests { }, } .into(); - let train_schedule_fail = train_schedule_fail - .create(&mut db_pool.get_ok()) - .await - .expect("Failed to create train schedule"); + + let train_schedule_fail = train_schedule_fail + .create(&mut db_pool.get_ok()) + .await + .expect("Failed to create train schedule"); + + let core = mocked_core_for_project_path(train_schedule_valid.id); + let app = TestAppBuilder::new() + .db_pool(db_pool.clone()) + .core_client(core.into()) + .build(); + + // TEST let request = app.post("/train_schedule/project_path").json(&json!({ "infra_id": small_infra.id, @@ -1094,7 +1165,7 @@ mod tests { "ids": vec![train_schedule_fail.id, train_schedule_valid.id], "path": { "track_section_ranges": [ - {"track_section": "fake_track", "begin": 0, "end": 100, "direction": "START_TO_STOP"} + {"track_section": "TA1", "begin": 0, "end": 100, "direction": "START_TO_STOP"} ], "routes": [], "blocks": []