diff --git a/backend/src/graphql/resolvers/RoomResolver.spec.ts b/backend/src/graphql/resolvers/RoomResolver.spec.ts index af19571e04..6041b289c1 100644 --- a/backend/src/graphql/resolvers/RoomResolver.spec.ts +++ b/backend/src/graphql/resolvers/RoomResolver.spec.ts @@ -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, @@ -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' })], }, }, }) diff --git a/backend/src/graphql/resolvers/RoomResolver.ts b/backend/src/graphql/resolvers/RoomResolver.ts index ad62e009b8..12a3f4c421 100644 --- a/backend/src/graphql/resolvers/RoomResolver.ts +++ b/backend/src/graphql/resolvers/RoomResolver.ts @@ -153,6 +153,7 @@ export class RoomResolver { m, joinMeetingLink({ fullName: user.name, + meetingID: m.meetingID, password: pw?.attendeePW ? pw.attendeePW : '', }), @@ -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 { + ): Promise { 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, diff --git a/frontend/src/pages/join-room/+Page.vue b/frontend/src/pages/join-room/+Page.vue index 23531fc352..a6972c880e 100644 --- a/frontend/src/pages/join-room/+Page.vue +++ b/frontend/src/pages/join-room/+Page.vue @@ -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() @@ -47,7 +48,6 @@ const userName = ref('') const form = ref() const { result: joinRoomQueryResult, - error: joinRoomQueryError, refetch: joinRoomQueryRefetch, loading, } = useQuery( @@ -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) } } diff --git a/frontend/src/pages/join-room/Page.test.ts b/frontend/src/pages/join-room/Page.test.ts index 1c2964bf21..2608aa031e 100644 --- a/frontend/src/pages/join-room/Page.test.ts +++ b/frontend/src/pages/join-room/Page.test.ts @@ -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' @@ -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' }), + ) }) }) })