Skip to content

Commit

Permalink
feat(backend): no logs in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mogge committed Apr 17, 2024
1 parent 378156d commit 08d5162
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions backend/src/graphql/resolvers/ContactFormResolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -14,7 +14,7 @@ jest.mock('#api/Brevo', () => {
})

beforeAll(async () => {
testServer = await createServer()
testServer = await createTestServer()
})

describe('ContactFormResolver', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -22,7 +22,7 @@ jest.mock('#api/Brevo', () => ({
}))

beforeAll(async () => {
testServer = await createServer()
testServer = await createTestServer()
})

describe('NewsletterSubscriptionResolver', () => {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/graphql/resolvers/RoomResolver.spec.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
12 changes: 9 additions & 3 deletions backend/src/server/server.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import { ApolloServer } from '@apollo/server'
import { ApolloServer, ApolloServerPlugin } from '@apollo/server'
import { startStandaloneServer } from '@apollo/server/standalone'

import { schema } from '#graphql/schema'

import { Context, getContextToken, GetContextToken } from './context'
import logger from './logger'

export const createServer = async (): Promise<ApolloServer> => {
export const createServer = async (withLogger: boolean = true): Promise<ApolloServer> => {
const plugins: ApolloServerPlugin<Context>[] = []
if (withLogger) plugins.push(logger)
return new ApolloServer<Context>({
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 },
Expand Down

0 comments on commit 08d5162

Please sign in to comment.