-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: setup the participant when initialize the room
- Loading branch information
1 parent
e877c35
commit 80ef952
Showing
6 changed files
with
126 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { Room } from './core'; | ||
import { ApiService } from './services/api'; | ||
import config from './services/config'; | ||
|
||
import { createRoom } from '.'; | ||
|
@@ -8,6 +9,8 @@ jest.mock('./services/api', () => ({ | |
validateApiKey: jest.fn(() => Promise.resolve(true)), | ||
fetchWaterMark: jest.fn(() => Promise.resolve({})), | ||
fetchLimits: jest.fn(() => Promise.resolve({})), | ||
createParticipant: jest.fn(() => Promise.resolve()), | ||
fetchParticipant: jest.fn(() => Promise.resolve(null)), | ||
}, | ||
})); | ||
|
||
|
@@ -254,4 +257,76 @@ describe('createRoom', () => { | |
|
||
expect(newRoom).not.toBe(room); | ||
}); | ||
|
||
test('should throw an error if the participant name is missing and the participant does not exist in the API', async () => { | ||
const params = { | ||
developerToken: 'abc123', | ||
roomId: 'abc123', | ||
participant: { | ||
id: 'abc123', | ||
}, | ||
group: { | ||
id: 'abc123', | ||
name: 'Group', | ||
}, | ||
environment: 'dev' as 'dev', | ||
}; | ||
|
||
const createRoomPromise = createRoom(params); | ||
|
||
await expect(createRoomPromise).rejects.toThrow( | ||
'[SuperViz | Room] - Participant does not exist, create the user in the API or add the name in the initialization to initialize the SuperViz room.', | ||
); | ||
}); | ||
|
||
test('should ignore the participant name if the participant exists in the API', async () => { | ||
const params = { | ||
developerToken: 'abc123', | ||
roomId: 'abc123', | ||
participant: { | ||
id: 'abc123', | ||
}, | ||
group: { | ||
id: 'abc123', | ||
name: 'Group', | ||
}, | ||
environment: 'dev' as 'dev', | ||
}; | ||
|
||
jest.spyOn(ApiService, 'fetchParticipant').mockResolvedValueOnce({ | ||
id: 'abc123', | ||
name: 'John Doe', | ||
email: '[email protected]', | ||
}); | ||
|
||
room = await createRoom(params); | ||
|
||
expect(room).toBeInstanceOf(Room); | ||
}); | ||
|
||
test('should create the participant if the participant does not exist in the API', async () => { | ||
const params = { | ||
developerToken: 'abc123', | ||
roomId: 'abc123', | ||
participant: { | ||
id: 'abc123', | ||
name: 'John Doe', | ||
}, | ||
group: { | ||
id: 'abc123', | ||
name: 'Group', | ||
}, | ||
environment: 'dev' as 'dev', | ||
}; | ||
|
||
jest.spyOn(ApiService, 'fetchParticipant').mockResolvedValueOnce(null); | ||
|
||
room = await createRoom(params); | ||
|
||
expect(ApiService.createParticipant).toHaveBeenCalledWith({ | ||
participantId: 'abc123', | ||
name: 'John Doe', | ||
email: undefined, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export type CreateParticipantParams = { | ||
name?: string; | ||
participantId: string; | ||
avatar?: string | null; | ||
email?: string | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters