mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
61 lines
1.8 KiB
TypeScript
61 lines
1.8 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,
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Returns a `ServerContext` object which can be passed to requests
|
|
* for testing.
|
|
*/
|
|
export function setupTestServerContext() {
|
|
const context: { [key: string] : any } = {};
|
|
|
|
const systems = [
|
|
InterchangeSystem.build(
|
|
{
|
|
id: "1", name: "Chapman University", passioSystemId: "263"
|
|
},
|
|
new InMemoryNotificationRepository()
|
|
),
|
|
]
|
|
|
|
beforeEach(() => {
|
|
context.systems = systems;
|
|
context.findSystemById = async (_: string) => 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 };
|
|
}
|