From 454e0227766b502023ef5a549d7879c819b9d07a Mon Sep 17 00:00:00 2001 From: Sandra Date: Thu, 20 Jun 2024 08:21:46 +0200 Subject: [PATCH 01/15] add errorcase for join Roomquery --- backend/src/graphql/resolvers/RoomResolver.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/graphql/resolvers/RoomResolver.ts b/backend/src/graphql/resolvers/RoomResolver.ts index 1014733d8e..3f82569b1a 100644 --- a/backend/src/graphql/resolvers/RoomResolver.ts +++ b/backend/src/graphql/resolvers/RoomResolver.ts @@ -99,13 +99,13 @@ export class RoomResolver { 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, From 926fd72e79e4e9cd616607327dd2713b15351a96 Mon Sep 17 00:00:00 2001 From: Sandra Date: Thu, 20 Jun 2024 09:16:06 +0200 Subject: [PATCH 02/15] modify test 'No room in DB' --- .../graphql/resolvers/RoomResolver.spec.ts | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/backend/src/graphql/resolvers/RoomResolver.spec.ts b/backend/src/graphql/resolvers/RoomResolver.spec.ts index a9d3691a42..6c5fa53d32 100644 --- a/backend/src/graphql/resolvers/RoomResolver.spec.ts +++ b/backend/src/graphql/resolvers/RoomResolver.spec.ts @@ -72,25 +72,20 @@ describe('RoomResolver', () => { } ` describe('No room in DB', () => { - it('returns null', async () => { - await expect( - testServer.executeOperation({ - query, - variables: { - userName: 'Pinky Pie', - roomId: 25, - }, - }), - ).resolves.toMatchObject({ - body: { - kind: 'single', - singleResult: { - data: { joinRoom: null }, - - errors: undefined, - }, + // beforeEach(()=> { + // joinMeetingLinkMock.mockRejectedValue({ errors: [{ message:'Error' }] }) + // }) + it('throws an Error', async () => { + expect(await testServer.executeOperation({ + query, + variables: { + userName: 'Pinky Pie', + roomId: 25, }, - }) + }), + ).resolves.toEqual( + expect.objectContaining({ errors:[{message: 'Room does not exist'}]}) + ) }) }) From 317a48162679462d9e24b62adc910988f299efe7 Mon Sep 17 00:00:00 2001 From: elweyn Date: Thu, 20 Jun 2024 09:38:32 +0200 Subject: [PATCH 03/15] remove nullable from query. Co-Authored-By: trinity2701 --- backend/src/graphql/resolvers/RoomResolver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/graphql/resolvers/RoomResolver.ts b/backend/src/graphql/resolvers/RoomResolver.ts index 3f82569b1a..64870b365a 100644 --- a/backend/src/graphql/resolvers/RoomResolver.ts +++ b/backend/src/graphql/resolvers/RoomResolver.ts @@ -95,7 +95,7 @@ export class RoomResolver { }) } - @Query(() => String, { nullable: true }) + @Query(() => String) async joinRoom( @Arg('userName') userName: string, @Arg('roomId', () => Int) roomId: number, From c4f3759599c3f6854f7a1590640f0e36d4e6ff2f Mon Sep 17 00:00:00 2001 From: elweyn Date: Thu, 20 Jun 2024 09:39:30 +0200 Subject: [PATCH 04/15] Test that query sends an error. Co-Authored-By: trinity2701 --- .../graphql/resolvers/RoomResolver.spec.ts | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/backend/src/graphql/resolvers/RoomResolver.spec.ts b/backend/src/graphql/resolvers/RoomResolver.spec.ts index 6c5fa53d32..79ec910491 100644 --- a/backend/src/graphql/resolvers/RoomResolver.spec.ts +++ b/backend/src/graphql/resolvers/RoomResolver.spec.ts @@ -72,20 +72,28 @@ describe('RoomResolver', () => { } ` describe('No room in DB', () => { - // beforeEach(()=> { - // joinMeetingLinkMock.mockRejectedValue({ errors: [{ message:'Error' }] }) - // }) it('throws an Error', async () => { - expect(await testServer.executeOperation({ - query, - variables: { - userName: 'Pinky Pie', - roomId: 25, + await expect( + testServer.executeOperation({ + query, + variables: { + userName: 'Pinky Pie', + roomId: 25, + }, + }), + ).resolves.toMatchObject({ + body: { + kind: 'single', + singleResult: { + data: null, + errors: [expect.objectContaining({ message: 'Room does not exist' })], + }, }, - }), - ).resolves.toEqual( - expect.objectContaining({ errors:[{message: 'Room does not exist'}]}) - ) + }) + + // .resolves.toEqual( + // expect.objectContaining({ errors: [{ message: 'Room does not exist' }] }), + // ) }) }) From b7dc6d8c5f23cffc3ddc97eb29aba783b119726e Mon Sep 17 00:00:00 2001 From: elweyn Date: Thu, 20 Jun 2024 10:08:32 +0200 Subject: [PATCH 05/15] Remove test on return null, and enabled test on error. --- frontend/src/pages/join-room/Page.test.ts | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/frontend/src/pages/join-room/Page.test.ts b/frontend/src/pages/join-room/Page.test.ts index 1c2964bf21..920c94ddca 100644 --- a/frontend/src/pages/join-room/Page.test.ts +++ b/frontend/src/pages/join-room/Page.test.ts @@ -1,4 +1,5 @@ -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' @@ -67,29 +68,17 @@ 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', () => { + describe('Error returned', () => { const consoleLogSpy = vi.spyOn(console, 'log') 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(consoleLogSpy).toBeCalledWith('Error', new ApolloError({ errorMessage: 'autsch' })) }) }) }) From 681d22da275406614e00476627a9d0c81320c5e1 Mon Sep 17 00:00:00 2001 From: elweyn Date: Thu, 20 Jun 2024 10:11:20 +0200 Subject: [PATCH 06/15] Change logic of interception of error to catch. Co-Authored-By: trinity2701 --- frontend/src/pages/join-room/+Page.vue | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/frontend/src/pages/join-room/+Page.vue b/frontend/src/pages/join-room/+Page.vue index 23531fc352..a8f62af062 100644 --- a/frontend/src/pages/join-room/+Page.vue +++ b/frontend/src/pages/join-room/+Page.vue @@ -47,7 +47,6 @@ const userName = ref('') const form = ref() const { result: joinRoomQueryResult, - error: joinRoomQueryError, refetch: joinRoomQueryRefetch, loading, } = useQuery( @@ -63,17 +62,14 @@ 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) { + // eslint-disable-next-line no-console + console.log('Error', error) } } From 3623f74f293d405a026a04ef9da56378da334110 Mon Sep 17 00:00:00 2001 From: Sandra Date: Thu, 20 Jun 2024 08:21:46 +0200 Subject: [PATCH 07/15] add errorcase for join Roomquery --- backend/src/graphql/resolvers/RoomResolver.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/graphql/resolvers/RoomResolver.ts b/backend/src/graphql/resolvers/RoomResolver.ts index 4c7e9676a9..d5a7f953a6 100644 --- a/backend/src/graphql/resolvers/RoomResolver.ts +++ b/backend/src/graphql/resolvers/RoomResolver.ts @@ -92,13 +92,13 @@ export class RoomResolver { 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, From 8f3d953e19fc7967b2306ec8bff4df85bc2d7741 Mon Sep 17 00:00:00 2001 From: Sandra Date: Thu, 20 Jun 2024 09:16:06 +0200 Subject: [PATCH 08/15] modify test 'No room in DB' --- .../graphql/resolvers/RoomResolver.spec.ts | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/backend/src/graphql/resolvers/RoomResolver.spec.ts b/backend/src/graphql/resolvers/RoomResolver.spec.ts index fd0ceb482c..2acbb0fbd0 100644 --- a/backend/src/graphql/resolvers/RoomResolver.spec.ts +++ b/backend/src/graphql/resolvers/RoomResolver.spec.ts @@ -97,25 +97,20 @@ describe('RoomResolver', () => { } ` describe('No room in DB', () => { - it('returns null', async () => { - await expect( - testServer.executeOperation({ - query, - variables: { - userName: 'Pinky Pie', - roomId: 25, - }, - }), - ).resolves.toMatchObject({ - body: { - kind: 'single', - singleResult: { - data: { joinRoom: null }, - - errors: undefined, - }, + // beforeEach(()=> { + // joinMeetingLinkMock.mockRejectedValue({ errors: [{ message:'Error' }] }) + // }) + it('throws an Error', async () => { + expect(await testServer.executeOperation({ + query, + variables: { + userName: 'Pinky Pie', + roomId: 25, }, - }) + }), + ).resolves.toEqual( + expect.objectContaining({ errors:[{message: 'Room does not exist'}]}) + ) }) }) From 105e88003c6d1907b8b98ed4cb20340da8552ca6 Mon Sep 17 00:00:00 2001 From: elweyn Date: Thu, 20 Jun 2024 10:18:29 +0200 Subject: [PATCH 09/15] Rebase to master. --- backend/src/graphql/resolvers/RoomResolver.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/src/graphql/resolvers/RoomResolver.ts b/backend/src/graphql/resolvers/RoomResolver.ts index d5a7f953a6..61489f0a99 100644 --- a/backend/src/graphql/resolvers/RoomResolver.ts +++ b/backend/src/graphql/resolvers/RoomResolver.ts @@ -75,12 +75,14 @@ export class RoomResolver { const { user } = context if (!user) return [] const meetings = await getMeetings() + // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call return meetings.map( (m: MeetingInfo) => new OpenRoom( m, joinMeetingLink({ fullName: user.name, + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access meetingID: m.meetingID, password: '', }), @@ -88,7 +90,7 @@ export class RoomResolver { ) } - @Query(() => String, { nullable: true }) + @Query(() => String) async joinRoom( @Arg('userName') userName: string, @Arg('roomId', () => Int) roomId: number, From b73ef0e0dbfd163ef4990afef43e43a587929e63 Mon Sep 17 00:00:00 2001 From: elweyn Date: Thu, 20 Jun 2024 09:39:30 +0200 Subject: [PATCH 10/15] Test that query sends an error. Co-Authored-By: trinity2701 --- .../graphql/resolvers/RoomResolver.spec.ts | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/backend/src/graphql/resolvers/RoomResolver.spec.ts b/backend/src/graphql/resolvers/RoomResolver.spec.ts index 2acbb0fbd0..f43eabde22 100644 --- a/backend/src/graphql/resolvers/RoomResolver.spec.ts +++ b/backend/src/graphql/resolvers/RoomResolver.spec.ts @@ -97,20 +97,28 @@ describe('RoomResolver', () => { } ` describe('No room in DB', () => { - // beforeEach(()=> { - // joinMeetingLinkMock.mockRejectedValue({ errors: [{ message:'Error' }] }) - // }) it('throws an Error', async () => { - expect(await testServer.executeOperation({ - query, - variables: { - userName: 'Pinky Pie', - roomId: 25, + await expect( + testServer.executeOperation({ + query, + variables: { + userName: 'Pinky Pie', + roomId: 25, + }, + }), + ).resolves.toMatchObject({ + body: { + kind: 'single', + singleResult: { + data: null, + errors: [expect.objectContaining({ message: 'Room does not exist' })], + }, }, - }), - ).resolves.toEqual( - expect.objectContaining({ errors:[{message: 'Room does not exist'}]}) - ) + }) + + // .resolves.toEqual( + // expect.objectContaining({ errors: [{ message: 'Room does not exist' }] }), + // ) }) }) From b2550d63af11844884f2af02ea336e1aef0b33a0 Mon Sep 17 00:00:00 2001 From: elweyn Date: Thu, 20 Jun 2024 10:08:32 +0200 Subject: [PATCH 11/15] Remove test on return null, and enabled test on error. --- frontend/src/pages/join-room/Page.test.ts | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/frontend/src/pages/join-room/Page.test.ts b/frontend/src/pages/join-room/Page.test.ts index 1c2964bf21..920c94ddca 100644 --- a/frontend/src/pages/join-room/Page.test.ts +++ b/frontend/src/pages/join-room/Page.test.ts @@ -1,4 +1,5 @@ -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' @@ -67,29 +68,17 @@ 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', () => { + describe('Error returned', () => { const consoleLogSpy = vi.spyOn(console, 'log') 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(consoleLogSpy).toBeCalledWith('Error', new ApolloError({ errorMessage: 'autsch' })) }) }) }) From 35190d75c56cd66c4f93b272a62569c0c4e5c1ae Mon Sep 17 00:00:00 2001 From: elweyn Date: Thu, 20 Jun 2024 10:11:20 +0200 Subject: [PATCH 12/15] Change logic of interception of error to catch. Co-Authored-By: trinity2701 --- frontend/src/pages/join-room/+Page.vue | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/frontend/src/pages/join-room/+Page.vue b/frontend/src/pages/join-room/+Page.vue index 23531fc352..a8f62af062 100644 --- a/frontend/src/pages/join-room/+Page.vue +++ b/frontend/src/pages/join-room/+Page.vue @@ -47,7 +47,6 @@ const userName = ref('') const form = ref() const { result: joinRoomQueryResult, - error: joinRoomQueryError, refetch: joinRoomQueryRefetch, loading, } = useQuery( @@ -63,17 +62,14 @@ 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) { + // eslint-disable-next-line no-console + console.log('Error', error) } } From 523e4e9b24129e44b4796b489af7e2d8066aae09 Mon Sep 17 00:00:00 2001 From: elweyn Date: Thu, 20 Jun 2024 10:28:14 +0200 Subject: [PATCH 13/15] Lint backend. Co-authored-by: Sandra --- backend/src/graphql/resolvers/RoomResolver.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/graphql/resolvers/RoomResolver.ts b/backend/src/graphql/resolvers/RoomResolver.ts index 61489f0a99..a90fd79b18 100644 --- a/backend/src/graphql/resolvers/RoomResolver.ts +++ b/backend/src/graphql/resolvers/RoomResolver.ts @@ -75,14 +75,14 @@ export class RoomResolver { const { user } = context if (!user) return [] const meetings = await getMeetings() - // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call + return meetings.map( (m: MeetingInfo) => new OpenRoom( m, joinMeetingLink({ fullName: user.name, - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access + meetingID: m.meetingID, password: '', }), From 60720f718969d3dedc50595b52a5b8601b4fdee5 Mon Sep 17 00:00:00 2001 From: elweyn Date: Thu, 20 Jun 2024 10:34:20 +0200 Subject: [PATCH 14/15] Remove commented code. Co-authored-by: Sandra --- backend/src/graphql/resolvers/RoomResolver.spec.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/backend/src/graphql/resolvers/RoomResolver.spec.ts b/backend/src/graphql/resolvers/RoomResolver.spec.ts index f43eabde22..cfd65fa91e 100644 --- a/backend/src/graphql/resolvers/RoomResolver.spec.ts +++ b/backend/src/graphql/resolvers/RoomResolver.spec.ts @@ -115,10 +115,6 @@ describe('RoomResolver', () => { }, }, }) - - // .resolves.toEqual( - // expect.objectContaining({ errors: [{ message: 'Room does not exist' }] }), - // ) }) }) From 9f9ede96c3bca345ef0bee9e9068b2aa64c9aace Mon Sep 17 00:00:00 2001 From: trinity2701 Date: Tue, 25 Jun 2024 12:21:48 +0200 Subject: [PATCH 15/15] add errorhandler and linting --- frontend/src/pages/join-room/+Page.vue | 4 ++-- frontend/src/pages/join-room/Page.test.ts | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/frontend/src/pages/join-room/+Page.vue b/frontend/src/pages/join-room/+Page.vue index a8f62af062..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() @@ -68,8 +69,7 @@ const getRoomLink = async () => { window.location.href = joinRoomQueryResult.value.joinRoom } } catch (error) { - // eslint-disable-next-line no-console - console.log('Error', 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 920c94ddca..2608aa031e 100644 --- a/frontend/src/pages/join-room/Page.test.ts +++ b/frontend/src/pages/join-room/Page.test.ts @@ -6,6 +6,7 @@ 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' @@ -69,7 +70,6 @@ describe('JoinRoomPage', () => { }) describe('Error returned', () => { - const consoleLogSpy = vi.spyOn(console, 'log') beforeEach(async () => { joinRoomQueryMock.mockRejectedValue({ message: 'autsch' }) await flushPromises() @@ -78,7 +78,10 @@ describe('JoinRoomPage', () => { }) it('logs Room not found', () => { - expect(consoleLogSpy).toBeCalledWith('Error', new ApolloError({ errorMessage: 'autsch' })) + expect(errorHandlerSpy).toBeCalledWith( + 'room link not found', + new ApolloError({ errorMessage: 'autsch' }), + ) }) }) })