-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathpaced-train.ts
30 lines (26 loc) · 1.14 KB
/
paced-train.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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;