From 77ebbd0bac3c4515fe4656f2ece3634f4220929e Mon Sep 17 00:00:00 2001
From: SharglutDev
Date: Fri, 28 Feb 2025 11:14:07 +0100
Subject: [PATCH] front: update e2e tests to handle paced trains
Signed-off-by: SharglutDev
---
front/tests/utils/paced-train.ts | 30 ++++++++++++++++++++++++++++++
front/tests/utils/setup-utils.ts | 2 +-
2 files changed, 31 insertions(+), 1 deletion(-)
create mode 100644 front/tests/utils/paced-train.ts
diff --git a/front/tests/utils/paced-train.ts b/front/tests/utils/paced-train.ts
new file mode 100644
index 00000000000..e86008ff3d5
--- /dev/null
+++ b/front/tests/utils/paced-train.ts
@@ -0,0 +1,30 @@
+import type { APIRequestContext, APIResponse } from '@playwright/test';
+
+import type { PacedTrainResult } from 'common/api/osrdEditoastApi';
+
+import { getApiContext, handleErrorResponse } from './api-utils';
+
+/**
+ * Send paced trains to the API for a specific timetable and returns the result.
+ *
+ * @param timetableId - The ID of the timetable for which the paced trains are being sent.
+ * @param body - The request payload containing paced train data.
+ * @returns {Promise} - The API response containing the train schedule results.
+ */
+async function sendPacedTrains(timetableId: number, body: JSON): Promise {
+ const apiContext: APIRequestContext = await getApiContext();
+ const pacedTrainsResponse: APIResponse = await apiContext.post(
+ `/api/timetable/${timetableId}/paced_trains/`,
+ {
+ data: JSON.stringify(body),
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ }
+ );
+ handleErrorResponse(pacedTrainsResponse, 'Failed to send paced train');
+ const responseData = (await pacedTrainsResponse.json()) as PacedTrainResult[];
+
+ return responseData;
+}
+export default sendPacedTrains;
diff --git a/front/tests/utils/setup-utils.ts b/front/tests/utils/setup-utils.ts
index 92e04b76da7..116d5f867f7 100644
--- a/front/tests/utils/setup-utils.ts
+++ b/front/tests/utils/setup-utils.ts
@@ -211,7 +211,7 @@ export async function createDataForTests(): Promise {
// Step 5: Create a scenario for the study
await createScenario(undefined, project.id, study.id, smallInfra.id);
- // Step 6: Create a project, study, scenario and import train schedule
+ // Step 6: Create a project, study, scenario and import train schedule and paced train data
const projectTrainSchedule = await createProject(trainScheduleProjectName);
const studyTrainSchedule = await createStudy(projectTrainSchedule.id, trainScheduleStudyName);
const scenarioTrainSchedule = (