From 7e747481393f9968ba60a43e991179fc2d8d27ef Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Wed, 16 Apr 2025 17:27:13 -0700 Subject: [PATCH] add integration test setup for parking data --- src/index.ts | 7 +++- src/loaders/parking/loadParkingTestData.ts | 33 +++++++++++++++++++ src/loaders/shuttle/loadShuttleTestData.ts | 10 +----- .../supportedIntegrationTestSystems.ts | 11 +++++++ 4 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 src/loaders/parking/loadParkingTestData.ts create mode 100644 src/loaders/supportedIntegrationTestSystems.ts diff --git a/src/index.ts b/src/index.ts index 46ac1ae..76a0839 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,9 +3,11 @@ import { ApolloServer } from "@apollo/server"; import { startStandaloneServer } from "@apollo/server/standalone"; import { MergedResolvers } from "./MergedResolvers"; import { ServerContext } from "./ServerContext"; -import { loadShuttleTestData, supportedIntegrationTestSystems } from "./loaders/shuttle/loadShuttleTestData"; +import { loadShuttleTestData } from "./loaders/shuttle/loadShuttleTestData"; import { InterchangeSystem, InterchangeSystemBuilderArguments } from "./entities/InterchangeSystem"; import { ChapmanApiBasedParkingRepositoryLoader } from "./loaders/parking/ChapmanApiBasedParkingRepositoryLoader"; +import { supportedIntegrationTestSystems } from "./loaders/supportedIntegrationTestSystems"; +import { loadParkingTestData } from "./loaders/parking/loadParkingTestData"; const typeDefs = readFileSync("./schema.graphqls", "utf8"); @@ -37,6 +39,9 @@ async function main() { // TODO: Have loading of different data for different systems in the future await loadShuttleTestData(system.shuttleRepository); + if (system.parkingRepository) { + await loadParkingTestData(system.parkingRepository); + } return system; } diff --git a/src/loaders/parking/loadParkingTestData.ts b/src/loaders/parking/loadParkingTestData.ts new file mode 100644 index 0000000..f73d15a --- /dev/null +++ b/src/loaders/parking/loadParkingTestData.ts @@ -0,0 +1,33 @@ +import { ParkingGetterSetterRepository } from "../../repositories/ParkingGetterSetterRepository"; +import { IParkingStructure } from "../../entities/ParkingRepositoryEntities"; + +const parkingStructures: IParkingStructure[] = [ + { + address: "300 E Walnut, Orange, CA 92867", + capacity: 871, + spotsAvailable: 211, + coordinates: { + latitude: 33.7945513, + longitude: -117.8518707, + }, + name: "Anderson Structure", + id: "1", + }, + { + address: "200 W Sycamore Ave, Orange, CA 92866-1053", + capacity: 692, + spotsAvailable: 282, + coordinates: { + latitude: 33.792937, + longitude: -117.854782 + }, + name: "Barrera", + id: "2", + } +]; + +export async function loadParkingTestData(repository: ParkingGetterSetterRepository) { + await Promise.all(parkingStructures.map(async structure => { + await repository.addOrUpdateParkingStructure(structure); + })) +} diff --git a/src/loaders/shuttle/loadShuttleTestData.ts b/src/loaders/shuttle/loadShuttleTestData.ts index c7603bf..c0c4e63 100644 --- a/src/loaders/shuttle/loadShuttleTestData.ts +++ b/src/loaders/shuttle/loadShuttleTestData.ts @@ -1,15 +1,7 @@ // Mock data import { IEta, IOrderedStop, IRoute, IShuttle, IStop } from "../../entities/ShuttleRepositoryEntities"; import { ShuttleGetterSetterRepository } from "../../repositories/ShuttleGetterSetterRepository"; -import { InterchangeSystemBuilderArguments } from "../../entities/InterchangeSystem"; - -export const supportedIntegrationTestSystems: InterchangeSystemBuilderArguments[] = [ - { - id: "1", - name: "Chapman University", - passioSystemId: "263", - }, -]; +import { supportedIntegrationTestSystems } from "../supportedIntegrationTestSystems"; const redRoutePolylineCoordinates = [ { diff --git a/src/loaders/supportedIntegrationTestSystems.ts b/src/loaders/supportedIntegrationTestSystems.ts new file mode 100644 index 0000000..8fd7d6d --- /dev/null +++ b/src/loaders/supportedIntegrationTestSystems.ts @@ -0,0 +1,11 @@ +import { InterchangeSystemBuilderArguments } from "../entities/InterchangeSystem"; +import { ChapmanApiBasedParkingRepositoryLoader } from "./parking/ChapmanApiBasedParkingRepositoryLoader"; + +export const supportedIntegrationTestSystems: InterchangeSystemBuilderArguments[] = [ + { + id: "1", + name: "Chapman University", + passioSystemId: "263", + parkingSystemId: ChapmanApiBasedParkingRepositoryLoader.id, + }, +];