Files
project-inter-server/testHelpers/apolloTestServerHelpers.ts
Claude fe649c81eb Change region to use top-left and bottom-right coordinates
Replace center+delta region representation with a bounding box defined
by topLeft and bottomRight coordinate pairs, which maps more directly
to the visible map area.

https://claude.ai/code/session_0162emnCi1KxW5FkTNn2ZrvH
2026-03-23 22:05:57 +00:00

73 lines
2.0 KiB
TypeScript

import { readFileSync } from "fs";
import { ApolloServer } from "@apollo/server";
import { MergedResolvers } from "../src/MergedResolvers";
import { beforeEach } from "@jest/globals";
import { ServerContext } from "../src/ServerContext";
import { InterchangeSystem, InterchangeSystemBuilderArguments } from "../src/entities/InterchangeSystem";
import {
ChapmanApiBasedParkingRepositoryLoader
} from "../src/loaders/parking/ChapmanApiBasedParkingRepositoryLoader";
function setUpTestServer() {
// Leaving this separate from the main server in case
// configuration changes
const typeDefs = readFileSync("./schema.graphqls", "utf8");
return new ApolloServer({
typeDefs,
resolvers: MergedResolvers,
});
}
const systemInfoForTesting: InterchangeSystemBuilderArguments = {
id: "1",
name: "Chapman University",
passioSystemId: "263",
parkingSystemId: ChapmanApiBasedParkingRepositoryLoader.id,
useSelfUpdatingEtas: false,
shuttleStopArrivalDegreeDelta: 0.001,
initialRegion: {
topLeft: { latitude: 33.7987, longitude: -117.8581 },
bottomRight: { latitude: 33.7887, longitude: -117.8481 },
},
};
export function buildSystemForTesting() {
return InterchangeSystem.buildForTesting(
systemInfoForTesting,
);
}
/**
* Returns a `ServerContext` object which can be passed to requests
* for testing.
*/
export function setupTestServerContext() {
const context: { [key: string] : any } = {};
beforeEach(() => {
context.systems = [
buildSystemForTesting(),
];
context.findSystemById = (_: string) => context.systems[0];
});
return context as ServerContext;
}
/**
* Returns an object which holds a test server.
* This server is reset before every test.
* Tests should keep a reference to the holder object,
* and not destructure it.
*/
export function setupTestServerHolder() {
const holder: { [key: string]: any } = {};
beforeEach(() => {
holder.testServer = setUpTestServer();
});
return holder as { testServer: ApolloServer };
}