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 26, 2024
2 parents c283d9f + 6bd7a7f commit e98d174
Show file tree
Hide file tree
Showing 26 changed files with 688 additions and 222 deletions.
4 changes: 2 additions & 2 deletions backend/jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"coverageThreshold": {
"global": {
"statements": 96,
"branches": 87,
"functions": 94,
"branches": 88,
"functions": 98,
"lines": 97
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE `Meeting` MODIFY `createTime` BIGINT NULL;
2 changes: 1 addition & 1 deletion backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ model Meeting {
createdAt DateTime @default(now())
voiceBridge Int?
dialNumber String? @db.VarChar(64)
createTime Int?
createTime BigInt?
createDate DateTime?
user User?
}
19 changes: 4 additions & 15 deletions backend/src/api/BBB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ export const createMeeting = async (
interface JoinMeetinLinkOptions {
fullName: string
meetingID: string
// role: 'MODERATOR' | 'VIEWER'
password: string
// createTime: string
// userID: string
role?: 'MODERATOR' | 'VIEWER'
password?: string
createTime?: string
userID?: string
}

export const joinMeetingLink = (options: JoinMeetinLinkOptions): string => {
Expand All @@ -185,17 +185,6 @@ export const joinMeetingLink = (options: JoinMeetinLinkOptions): string => {
return CONFIG.BBB_URL + 'join?' + params + '&checksum=' + checksum
}

const handleOpenRomms = async (): Promise<void> => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const rooms = await getMeetings()
// console.log(rooms.map((m) => m.attendees?.attendee))
}

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

/*
export const listHooks = async () => {
try {
Expand Down
13 changes: 6 additions & 7 deletions backend/src/auth/authChecker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@ describe('authChecker', () => {
it('returns access denied error', async () => {
await expect(
testServer.executeOperation({
query: 'query { joinMyRoom }',
query: 'mutation { joinMyRoom }',
}),
).resolves.toMatchObject({
body: {
kind: 'single',
singleResult: {
data: {
joinMyRoom: null,
},
data: null,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
errors: expect.arrayContaining([
expect.objectContaining({
Expand All @@ -69,7 +67,7 @@ describe('authChecker', () => {
it('creates user in database', async () => {
await testServer.executeOperation(
{
query: 'query { joinMyRoom }',
query: 'mutation { joinMyRoom }',
},
{
contextValue: {
Expand All @@ -88,7 +86,8 @@ describe('authChecker', () => {
createdAt: expect.any(Date),
name: 'User',
username: 'mockedUser',
meetingId: null,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
meetingId: expect.any(Number),
},
])
})
Expand Down Expand Up @@ -117,7 +116,7 @@ describe('authChecker', () => {
it('has the same user in database', async () => {
await testServer.executeOperation(
{
query: 'query { joinMyRoom }',
query: 'mutation { joinMyRoom }',
},
{
contextValue: {
Expand Down
196 changes: 165 additions & 31 deletions backend/src/graphql/resolvers/RoomResolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ describe('RoomResolver', () => {
it('throws access denied', async () => {
await expect(
testServer.executeOperation({
query: 'query { joinMyRoom }',
query: 'mutation { joinMyRoom }',
}),
).resolves.toMatchObject({
body: {
kind: 'single',
singleResult: {
data: { joinMyRoom: null },
data: null,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
errors: expect.arrayContaining([
expect.objectContaining({
Expand Down Expand Up @@ -288,74 +288,189 @@ describe('RoomResolver', () => {
})

describe('joinMyRoom', () => {
describe('createMeeting returns undefined', () => {
it('returns null', async () => {
createMeetingMock.mockResolvedValue(null)
beforeAll(async () => {
await prisma.meeting.deleteMany()
await prisma.user.deleteMany()
})

let meetingId: string | undefined

describe('meeting does not exist', () => {
joinMeetingLinkMock.mockReturnValue('https://my-link')
createMeetingMock.mockResolvedValue({
returncode: 'SUCCESS',
meetingID: 'xxx',
internalMeetingID: 'b60d121b438a380c343d5ec3c2037564b82ffef3-1715231322715',
parentMeetingID: 'bbb-none',
attendeePW: 'w3VUvMcp',
moderatorPW: 'MyPp9Zfq',
createTime: 1718189921310,
voiceBridge: 255,
dialNumber: '613-555-1234',
createDate: new Date(),
hasUserJoined: false,
duration: 0,
hasBeenForciblyEnded: false,
messageKey: '',
message: '',
})

it('returns link to room', async () => {
await expect(
testServer.executeOperation(
{
query: 'query { joinMyRoom }',
query: 'mutation { joinMyRoom }',
},
{
contextValue: {
token: 'token',
user: undefined,
},
},
),
).resolves.toMatchObject({
body: {
kind: 'single',
singleResult: {
data: { joinMyRoom: null },
data: {
joinMyRoom: 'https://my-link',
},
errors: undefined,
},
},
})
})
})

describe('createMeeting returns meeting', () => {
it('returns link to the meeting', async () => {
joinMeetingLinkMock.mockReturnValue('https://my-link')
createMeetingMock.mockResolvedValue({
returncode: 'SUCCESS',
meetingID: 'xxx',
internalMeetingID: 'b60d121b438a380c343d5ec3c2037564b82ffef3-1715231322715',
parentMeetingID: 'bbb-none',
attendeePW: 'w3VUvMcp',
moderatorPW: 'MyPp9Zfq',
createTime: 1715231322715,
voiceBridge: 255,
dialNumber: '613-555-1234',
createDate: new Date(),
hasUserJoined: false,
duration: 0,
hasBeenForciblyEnded: false,
messageKey: '',
message: '',
it('creates meeting in database', async () => {
const result = await prisma.user.findFirst({
include: {
meeting: true,
},
})
meetingId = result?.meeting?.meetingID
expect(result).toMatchObject({
meeting: {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
id: expect.any(Number),
name: 'mockedUser',
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
meetingID: expect.any(String),
attendeePW: 'w3VUvMcp',
moderatorPW: 'MyPp9Zfq',
voiceBridge: 255,
dialNumber: '613-555-1234',
createTime: 1718189921310n,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
createDate: expect.any(Date),
},
})
})
})

describe('meeting exists in DB', () => {
beforeAll(() => {
jest.clearAllMocks()
})

joinMeetingLinkMock.mockReturnValue('https://my-link')
createMeetingMock.mockResolvedValue({
returncode: 'SUCCESS',
meetingID: 'xxx',
internalMeetingID: 'b60d121b438a380c343d5ec3c2037564b82ffef3-1715231322715',
parentMeetingID: 'bbb-none',
attendeePW: 'w3VUvMcp',
moderatorPW: 'MyPp9Zfq',
createTime: 1718189921310,
voiceBridge: 255,
dialNumber: '613-555-1234',
createDate: new Date(),
hasUserJoined: false,
duration: 0,
hasBeenForciblyEnded: false,
messageKey: '',
message: '',
})

it('returns link to room', async () => {
await expect(
testServer.executeOperation(
{
query: 'query { joinMyRoom }',
query: 'mutation { joinMyRoom }',
},
{
contextValue: {
token: 'token',
user: undefined,
},
},
),
).resolves.toMatchObject({
body: {
kind: 'single',
singleResult: {
data: { joinMyRoom: 'https://my-link' },
data: {
joinMyRoom: 'https://my-link',
},
errors: undefined,
},
},
})
})

it('updates meeting in database', async () => {
await expect(
prisma.user.findFirst({
include: {
meeting: true,
},
}),
).resolves.toMatchObject({
meeting: {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
id: expect.any(Number),
name: 'mockedUser',
meetingID: meetingId,
attendeePW: 'w3VUvMcp',
moderatorPW: 'MyPp9Zfq',
voiceBridge: 255,
dialNumber: '613-555-1234',
createTime: 1718189921310n,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
createDate: expect.any(Date),
},
})
})
})

describe('createMeeting returns undefined', () => {
it('throws meeting error', async () => {
createMeetingMock.mockResolvedValue(null)
await expect(
testServer.executeOperation(
{
query: 'mutation { joinMyRoom }',
},
{
contextValue: {
token: 'token',
},
},
),
).resolves.toMatchObject({
body: {
kind: 'single',
singleResult: {
data: null,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
errors: expect.arrayContaining([
expect.objectContaining({
message: 'Could not create meeting!',
}),
]),
},
},
})
})
})
})

Expand Down Expand Up @@ -458,7 +573,17 @@ describe('RoomResolver', () => {
})
})

describe('one attendee', () => {
describe('one attendee and meeting in DB', () => {
beforeAll(async () => {
await prisma.meeting.create({
data: {
name: 'Dreammall Entwicklung',
meetingID: 'Dreammall-Entwicklung',
attendeePW: '1234',
},
})
})

beforeEach(() => {
getMeetingsMock.mockResolvedValue([
{
Expand Down Expand Up @@ -502,7 +627,8 @@ describe('RoomResolver', () => {
])
})

it('returns empty array', async () => {
it('returns room with attendee', async () => {
jest.clearAllMocks()
await expect(
testServer.executeOperation(
{
Expand Down Expand Up @@ -540,6 +666,14 @@ describe('RoomResolver', () => {
},
})
})

it('calls joinMeetingLink with correct PW', () => {
expect(joinMeetingLinkMock).toBeCalledWith({
fullName: 'User',
meetingID: 'Dreammall-Entwicklung',
password: '1234',
})
})
})

describe('some attendee', () => {
Expand Down
Loading

0 comments on commit e98d174

Please sign in to comment.