Skip to content

Commit

Permalink
Merge pull request #1190 from dreammall-earth/724-JoinMeetingPage
Browse files Browse the repository at this point in the history
feat(frontend): add errorcase for join Roomquery
  • Loading branch information
trinity2701 authored Jun 27, 2024
2 parents 6bd7a7f + e0fc418 commit d8da60f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 34 deletions.
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
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 d8da60f

Please sign in to comment.