mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
65 lines
1.9 KiB
TypeScript
65 lines
1.9 KiB
TypeScript
import { readFileSync } from "fs";
|
|
import { ApolloServer } from "@apollo/server";
|
|
import { MergedResolvers } from "../../src/MergedResolvers";
|
|
import { UnoptimizedInMemoryShuttleRepository } from "../../src/repositories/UnoptimizedInMemoryShuttleRepository";
|
|
import { beforeEach } from "@jest/globals";
|
|
import { ServerContext } from "../../src/ServerContext";
|
|
import { ETANotificationScheduler } from "../../src/notifications/schedulers/ETANotificationScheduler";
|
|
import { InMemoryNotificationRepository } from "../../src/repositories/InMemoryNotificationRepository";
|
|
import { InterchangeSystem } from "../../src/entities/InterchangeSystem";
|
|
|
|
|
|
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 = {
|
|
id: "1", name: "Chapman University", passioSystemId: "263"
|
|
};
|
|
|
|
export function buildSystemForTesting() {
|
|
return InterchangeSystem.build(
|
|
systemInfoForTesting,
|
|
new InMemoryNotificationRepository()
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 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 };
|
|
}
|