Extract setupRouteAndOrderedStops to a test helper

This commit is contained in:
2025-11-11 12:21:26 -08:00
parent 83e3414c8e
commit e0b00d1887
2 changed files with 64 additions and 55 deletions

View File

@@ -0,0 +1,62 @@
import { IOrderedStop } from "../src/entities/ShuttleRepositoryEntities";
import { ShuttleGetterSetterRepository } from "../src/repositories/shuttle/ShuttleGetterSetterRepository";
export async function setupRouteAndOrderedStopsForShuttleRepository(
shuttleRepository: ShuttleGetterSetterRepository
) {
const systemId = "sys1";
const route = {
id: "r1",
name: "Route 1",
color: "red",
systemId: systemId,
polylineCoordinates: [],
updatedTime: new Date(),
};
await shuttleRepository.addOrUpdateRoute(route);
const stop1 = {
id: "st1",
name: "Stop 1",
systemId: systemId,
coordinates: { latitude: 10.0, longitude: 20.0 },
updatedTime: new Date(),
};
const stop2 = {
id: "st2",
name: "Stop 2",
systemId: systemId,
coordinates: { latitude: 15.0, longitude: 25.0 },
updatedTime: new Date(),
};
await shuttleRepository.addOrUpdateStop(stop1);
await shuttleRepository.addOrUpdateStop(stop2);
const orderedStop1: IOrderedStop = {
routeId: route.id,
stopId: stop1.id,
position: 1,
systemId: systemId,
updatedTime: new Date(),
};
const orderedStop2: IOrderedStop = {
routeId: route.id,
stopId: stop2.id,
position: 2,
systemId: systemId,
updatedTime: new Date(),
};
orderedStop1.nextStop = orderedStop2;
orderedStop1.previousStop = orderedStop2;
orderedStop2.nextStop = orderedStop1;
orderedStop2.previousStop = orderedStop1;
await shuttleRepository.addOrUpdateOrderedStop(orderedStop1);
await shuttleRepository.addOrUpdateOrderedStop(orderedStop2);
return {
route,
systemId,
stop1,
stop2,
};
}