Skip to content

Commit

Permalink
front: update e2e tests to handle paced trains
Browse files Browse the repository at this point in the history
Signed-off-by: SharglutDev <[email protected]>
  • Loading branch information
SharglutDev committed Mar 7, 2025
1 parent a8611cb commit 77ebbd0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions front/tests/utils/paced-train.ts
Original file line number Diff line number Diff line change
@@ -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<PacedTrainResult[]>} - The API response containing the train schedule results.
*/
async function sendPacedTrains(timetableId: number, body: JSON): Promise<PacedTrainResult[]> {
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;
2 changes: 1 addition & 1 deletion front/tests/utils/setup-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export async function createDataForTests(): Promise<void> {
// 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 = (
Expand Down

0 comments on commit 77ebbd0

Please sign in to comment.