Skip to content

Commit

Permalink
Merge branch 'master' into 714-feature-end-to-end-enter-room
Browse files Browse the repository at this point in the history
  • Loading branch information
mahula authored Jun 27, 2024
2 parents 86b0241 + 0a786fa commit 4576caf
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 44 deletions.
6 changes: 3 additions & 3 deletions backend/jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"coverageThreshold": {
"global": {
"statements": 96,
"branches": 88,
"functions": 98,
"lines": 97
"branches": 86,
"functions": 96,
"lines": 96
}
},
"modulePathIgnorePatterns": ["<rootDir>/build/"],
Expand Down
1 change: 1 addition & 0 deletions backend/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const BREVO = {
const BBB = {
BBB_SHARED_SECRET: process.env.BBB_SHARED_SECRET ?? 'unknown',
BBB_URL: process.env.BBB_URL ?? 'https://my.url',
BBB_PULL_MEETINGS: process.env.NODE_ENV !== 'test' && process.env.BBB_URL,
}

export const CONFIG = {
Expand Down
7 changes: 3 additions & 4 deletions backend/src/graphql/resolvers/RoomResolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe('RoomResolver', () => {
}
`
describe('No room in DB', () => {
it('returns null', async () => {
it('throws an Error', async () => {
await expect(
testServer.executeOperation({
query,
Expand All @@ -110,9 +110,8 @@ describe('RoomResolver', () => {
body: {
kind: 'single',
singleResult: {
data: { joinRoom: null },

errors: undefined,
data: null,
errors: [expect.objectContaining({ message: 'Room does not exist' })],
},
},
})
Expand Down
7 changes: 4 additions & 3 deletions backend/src/graphql/resolvers/RoomResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export class RoomResolver {
m,
joinMeetingLink({
fullName: user.name,

meetingID: m.meetingID,
password: pw?.attendeePW ? pw.attendeePW : '',
}),
Expand All @@ -162,17 +163,17 @@ export class RoomResolver {
return []
}

@Query(() => String, { nullable: true })
@Query(() => String)
async joinRoom(
@Arg('userName') userName: string,
@Arg('roomId', () => Int) roomId: number,
): Promise<string | null> {
): Promise<string> {
const meeting = await prisma.meeting.findUnique({
where: {
id: roomId,
},
})
if (!meeting) return null
if (!meeting) throw new Error('Room does not exist')
return joinMeetingLink({
fullName: userName,
meetingID: meeting.meetingID,
Expand Down
5 changes: 5 additions & 0 deletions backend/src/graphql/resolvers/dal/handleOpenRooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ export const handleOpenRooms = async (): Promise<void> => {
},
})
}

export const checkForOpenRooms = (): void => {
void handleOpenRooms()
setTimeout(checkForOpenRooms, 60 * 1000)
}
4 changes: 4 additions & 0 deletions backend/src/graphql/schema.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { GraphQLSchema } from 'graphql'
import { buildSchema } from 'type-graphql'

import { CONFIG } from '#config/config'
import { authChecker } from '#src/auth/authChecker'

import { ContactFormResolver } from './resolvers/ContactFormResolver'
import { checkForOpenRooms } from './resolvers/dal/handleOpenRooms'
import { NewsletterSubscriptionResolver } from './resolvers/NewsletterSubscriptionResolver'
import { RoomResolver } from './resolvers/RoomResolver'

if (CONFIG.BBB_PULL_MEETINGS) void checkForOpenRooms()

export const schema = async (): Promise<GraphQLSchema> => {
return buildSchema({
resolvers: [ContactFormResolver, NewsletterSubscriptionResolver, RoomResolver],
Expand Down
7 changes: 0 additions & 7 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
// eslint-disable-next-line import/no-unassigned-import
import 'reflect-metadata'
import { handleOpenRooms } from '#graphql/resolvers/dal/handleOpenRooms'

import logger from './logger'
import { prisma } from './prisma'
import { listen } from './server/server'

const checkForOpenRooms = (): void => {
void handleOpenRooms()
setTimeout(checkForOpenRooms, 60 * 1000)
}

export const main = async (): Promise<void> => {
const url = await listen(4000)
logger.info(`🚀 Server is ready at ${url}`)
checkForOpenRooms()
}

void main()
Expand Down
16 changes: 6 additions & 10 deletions frontend/src/pages/join-room/+Page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { ref } from 'vue'
import MainButton from '#components/buttons/MainButton.vue'
import { usePageContext } from '#context/usePageContext'
import DefaultLayout from '#layouts/DefaultLayout.vue'
import GlobalErrorHandler from '#plugins/globalErrorHandler'
import { joinRoomQuery } from '#queries/joinRoomQuery'
const pageContext = usePageContext()
Expand All @@ -47,7 +48,6 @@ const userName = ref('')
const form = ref<HTMLFormElement>()
const {
result: joinRoomQueryResult,
error: joinRoomQueryError,
refetch: joinRoomQueryRefetch,
loading,
} = useQuery(
Expand All @@ -63,17 +63,13 @@ const {
)
const getRoomLink = async () => {
await joinRoomQueryRefetch()
if (joinRoomQueryError.value) {
// eslint-disable-next-line no-console
console.log('Error', joinRoomQueryError.value.message)
} else {
if (joinRoomQueryResult.value.joinRoom) {
try {
await joinRoomQueryRefetch()
if (joinRoomQueryResult.value) {
window.location.href = joinRoomQueryResult.value.joinRoom
} else {
// eslint-disable-next-line no-console
console.log('Room not found')
}
} catch (error) {
GlobalErrorHandler.error('room link not found', error)
}
}
</script>
26 changes: 9 additions & 17 deletions frontend/src/pages/join-room/Page.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { mount } from '@vue/test-utils'
import { ApolloError } from '@apollo/client/errors'
import { flushPromises, mount } from '@vue/test-utils'
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { Component, h } from 'vue'
import { VApp } from 'vuetify/components'

import { joinRoomQuery } from '#queries/joinRoomQuery'
import { mockClient } from '#tests/mock.apolloClient'
import { errorHandlerSpy } from '#tests/plugin.globalErrorHandler'

import JoinRoomPage from './+Page.vue'
import Route from './+route'
Expand Down Expand Up @@ -67,29 +69,19 @@ describe('JoinRoomPage', () => {
})
})

describe('Null returned', () => {
const consoleLogSpy = vi.spyOn(console, 'log')
beforeEach(async () => {
joinRoomQueryMock.mockResolvedValue({ data: { joinRoom: null } })
vi.clearAllMocks()
await wrapper.find('form').trigger('submit')
})

it('logs Room not found', () => {
expect(consoleLogSpy).toBeCalledWith('Room not found')
})
})

describe.skip('Error returned', () => {
const consoleLogSpy = vi.spyOn(console, 'log')
describe('Error returned', () => {
beforeEach(async () => {
joinRoomQueryMock.mockRejectedValue({ message: 'autsch' })
await flushPromises()
vi.clearAllMocks()
await wrapper.find('form').trigger('submit')
})

it('logs Room not found', () => {
expect(consoleLogSpy).toBeCalledWith('Error', 'autsch')
expect(errorHandlerSpy).toBeCalledWith(
'room link not found',
new ApolloError({ errorMessage: 'autsch' }),
)
})
})
})
Expand Down

0 comments on commit 4576caf

Please sign in to comment.