update test helpers to consolidate ServerContext creation into one method

This commit is contained in:
2025-02-04 10:56:00 -08:00
parent 814f2c6584
commit b918bf7a67
9 changed files with 63 additions and 41 deletions

View File

@@ -4,6 +4,7 @@ import { MergedResolvers } from "../../src/MergedResolvers";
import { UnoptimizedInMemoryRepository } from "../../src/repositories/UnoptimizedInMemoryRepository";
import { beforeEach } from "@jest/globals";
import { ServerContext } from "../../src/ServerContext";
import { NotificationService } from "../../src/services/NotificationService";
function setUpTestServer() {
@@ -17,14 +18,28 @@ function setUpTestServer() {
}
export function setupTestServerContext() {
// @ts-ignore
const context: { testServer: ApolloServer<ServerContext>; repository: UnoptimizedInMemoryRepository } = {};
const context: { [key: string] : any } = {};
beforeEach(() => {
context.testServer = setUpTestServer();
context.repository = new UnoptimizedInMemoryRepository();
context.notificationService = new NotificationService(context.repository);
});
// Return a reference, not destructured values
return context;
}
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 };
}