From 08d516275a945abdd3f82c5c8c646c1295133f0a Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 17 Apr 2024 14:54:12 +0200 Subject: [PATCH] feat(backend): no logs in unit tests --- .../graphql/resolvers/ContactFormResolver.spec.ts | 4 ++-- .../resolvers/NewsletterSubscriptionResolver.spec.ts | 4 ++-- backend/src/graphql/resolvers/RoomResolver.spec.ts | 4 ++-- backend/src/server/server.ts | 12 +++++++++--- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/backend/src/graphql/resolvers/ContactFormResolver.spec.ts b/backend/src/graphql/resolvers/ContactFormResolver.spec.ts index 20af0396bc..d34e59c225 100644 --- a/backend/src/graphql/resolvers/ContactFormResolver.spec.ts +++ b/backend/src/graphql/resolvers/ContactFormResolver.spec.ts @@ -3,7 +3,7 @@ import { ApolloServer } from '@apollo/server' import { sendContactEmails } from '#api/Brevo' import { EventType } from '#src/event/EventType' import { prisma } from '#src/prisma' -import { createServer } from '#src/server/server' +import { createTestServer } from '#src/server/server' let testServer: ApolloServer @@ -14,7 +14,7 @@ jest.mock('#api/Brevo', () => { }) beforeAll(async () => { - testServer = await createServer() + testServer = await createTestServer() }) describe('ContactFormResolver', () => { diff --git a/backend/src/graphql/resolvers/NewsletterSubscriptionResolver.spec.ts b/backend/src/graphql/resolvers/NewsletterSubscriptionResolver.spec.ts index a5c9ca778b..697d246c65 100644 --- a/backend/src/graphql/resolvers/NewsletterSubscriptionResolver.spec.ts +++ b/backend/src/graphql/resolvers/NewsletterSubscriptionResolver.spec.ts @@ -4,7 +4,7 @@ import { confirmNewsletter, subscribeToNewsletter } from '#api/Brevo' import { CONFIG } from '#config/config' import { EventType } from '#src/event/EventType' import { prisma } from '#src/prisma' -import { createServer } from '#src/server/server' +import { createTestServer } from '#src/server/server' CONFIG.BREVO_KEY = 'MY KEY' CONFIG.BREVO_ADMIN_NAME = 'Bibi Bloxberg' @@ -22,7 +22,7 @@ jest.mock('#api/Brevo', () => ({ })) beforeAll(async () => { - testServer = await createServer() + testServer = await createTestServer() }) describe('NewsletterSubscriptionResolver', () => { diff --git a/backend/src/graphql/resolvers/RoomResolver.spec.ts b/backend/src/graphql/resolvers/RoomResolver.spec.ts index 9f51b2b4d5..1c1853e2f4 100644 --- a/backend/src/graphql/resolvers/RoomResolver.spec.ts +++ b/backend/src/graphql/resolvers/RoomResolver.spec.ts @@ -1,14 +1,14 @@ import { ApolloServer } from '@apollo/server' import { CONFIG } from '#config/config' -import { createServer } from '#src/server/server' +import { createTestServer } from '#src/server/server' CONFIG.ROOM_LINK = 'http://bbb.dreammall.earth' let testServer: ApolloServer beforeAll(async () => { - testServer = await createServer() + testServer = await createTestServer() }) describe('RoomResolver', () => { diff --git a/backend/src/server/server.ts b/backend/src/server/server.ts index d0de9fac59..773cff5fdb 100644 --- a/backend/src/server/server.ts +++ b/backend/src/server/server.ts @@ -1,4 +1,4 @@ -import { ApolloServer } from '@apollo/server' +import { ApolloServer, ApolloServerPlugin } from '@apollo/server' import { startStandaloneServer } from '@apollo/server/standalone' import { schema } from '#graphql/schema' @@ -6,13 +6,19 @@ import { schema } from '#graphql/schema' import { Context, getContextToken, GetContextToken } from './context' import logger from './logger' -export const createServer = async (): Promise => { +export const createServer = async (withLogger: boolean = true): Promise => { + const plugins: ApolloServerPlugin[] = [] + if (withLogger) plugins.push(logger) return new ApolloServer({ schema: await schema(), - plugins: [logger], + plugins, }) } +export const createTestServer = async () => { + return await createServer(false) +} + export async function listen(port: number, getToken: GetContextToken = getContextToken) { const { url } = await startStandaloneServer(await createServer(), { listen: { port },