-
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.
Merge pull request #199 from SuperViz/feat/new-room-oackage-params
feat: assiging slots to the participants
- Loading branch information
Showing
5 changed files
with
384 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
export const NAME_IS_WHITE_TEXT = [ | ||
'rosybrown', | ||
'red', | ||
'saddlebrown', | ||
'coral', | ||
'orange', | ||
'brown', | ||
'goldenrod', | ||
'olivegreen', | ||
'darkolivegreen', | ||
'seagreen', | ||
'lightsea', | ||
'teal', | ||
'cadetblue', | ||
'pastelblue', | ||
'mediumslateblue', | ||
'bluedark', | ||
'navy', | ||
'rebeccapurple', | ||
'purple', | ||
'vividorchid', | ||
'darkmagenta', | ||
'deepmagenta', | ||
'fuchsia', | ||
'violetred', | ||
'pink', | ||
'vibrantpink', | ||
'paleredviolet', | ||
'carmine', | ||
'wine', | ||
]; | ||
|
||
export const MEETING_COLORS = { | ||
turquoise: '#31E0B0', | ||
orange: '#FF5E10', | ||
blue: '#00ABF7', | ||
pink: '#FF00BB', | ||
purple: '#9C29FF', | ||
green: '#6FDD00', | ||
red: '#E30000', | ||
bluedark: '#304AFF', | ||
pinklight: '#FF89C4', | ||
purplelight: '#D597FF', | ||
greenlight: '#C6EC5C', | ||
orangelight: '#FFA115', | ||
bluelight: '#75DEFE', | ||
redlight: '#FAA291', | ||
brown: '#BB813F', | ||
yellow: '#FFEF33', | ||
olivegreen: '#93A000', | ||
lightyellow: '#FAE391', | ||
violetred: '#C03FA3', | ||
rosybrown: '#B58787', | ||
cadetblue: '#2095BB', | ||
lightsteelblue: '#ABB5FF', | ||
seagreen: '#04B45F', | ||
palegreen: '#8DE990', | ||
saddlebrown: '#964C42', | ||
pastelblue: '#77A1CC', | ||
palesilver: '#D2BABA', | ||
coral: '#DF6B6B', | ||
bisque: '#FFD9C4', | ||
goldenrod: '#DAA520', | ||
tan: '#D2BD93', | ||
darkolivegreen: '#536C27', | ||
mint: '#ADE6DF', | ||
lightsea: '#45AFAA', | ||
teal: '#036E6E', | ||
wine: '#760040', | ||
cyan: '#00FFFF', | ||
mediumslateblue: '#6674D7', | ||
navy: '#0013BB', | ||
rebeccapurple: '#663399', | ||
vividorchid: '#D429FF', | ||
darkmagenta: '#810E81', | ||
deepmagenta: '#C303C6', | ||
fuchsia: '#FA00FF', | ||
lavendermagenta: '#EE82EE', | ||
thistle: '#EEB4DD', | ||
vibrantpink: '#FF007A', | ||
cottoncandy: '#FFC0DE', | ||
paleredviolet: '#D96598', | ||
carmine: '#B50A52', | ||
gray: '#878291', | ||
}; | ||
|
||
export const MEETING_COLORS_ARRAY = Object.values(MEETING_COLORS); | ||
export const MEETING_COLORS_KEYS = Object.keys(MEETING_COLORS); |
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,92 @@ | ||
import { PresenceEvent, PresenceEvents, Room } from '@superviz/socket-client'; | ||
|
||
import { Participant, Slot } from '../../common/types/participant.types'; | ||
|
||
import { SlotService } from './index'; | ||
|
||
describe('SlotService', () => { | ||
let room: Room; | ||
let participant: Participant; | ||
let slotService: SlotService; | ||
|
||
beforeEach(() => { | ||
room = { | ||
presence: { | ||
on: jest.fn(), | ||
get: jest.fn(), | ||
update: jest.fn(), | ||
}, | ||
} as unknown as Room; | ||
|
||
participant = { | ||
id: 'participant1', | ||
slot: SlotService.getDefaultSlot(), | ||
} as Participant; | ||
|
||
slotService = new SlotService(room, participant); | ||
}); | ||
|
||
it('should initialize with default slot', () => { | ||
expect(slotService.slot).toEqual({ | ||
...SlotService.getDefaultSlot(), | ||
timestamp: expect.any(Number), | ||
}); | ||
}); | ||
|
||
it('should assign a slot to the participant', async () => { | ||
room.presence.get = jest.fn((callback) => callback([])); | ||
room.presence.update = jest.fn(); | ||
|
||
const slot = await slotService['assignSlot'](); | ||
|
||
expect(slot).toBeDefined(); | ||
expect(slot.index).toBeGreaterThanOrEqual(0); | ||
expect(slot.index).toBeLessThan(50); | ||
expect(room.presence.update).toHaveBeenCalledWith({ slot }); | ||
}); | ||
|
||
it('should handle presence update for the same participant', async () => { | ||
const event: PresenceEvent<Participant> = { | ||
id: participant.id, | ||
data: { slot: { index: 1 } }, | ||
} as PresenceEvent<Participant>; | ||
|
||
slotService['validateSlotType'] = jest.fn().mockResolvedValue({ index: 1 }); | ||
|
||
await slotService['onPresenceUpdate'](event); | ||
|
||
expect(slotService['validateSlotType']).toHaveBeenCalledWith(event.data); | ||
expect(participant.slot.index).toBe(1); | ||
}); | ||
|
||
it('should set default slot', () => { | ||
slotService['setDefaultSlot'](); | ||
|
||
expect(slotService.slot).toEqual(SlotService.getDefaultSlot()); | ||
expect(room.presence.update).toHaveBeenCalledWith({ slot: SlotService.getDefaultSlot() }); | ||
}); | ||
|
||
it('should validate and assign slot type', async () => { | ||
slotService['assignSlot'] = jest.fn().mockResolvedValue({ index: 1 }); | ||
slotService['setDefaultSlot'] = jest.fn(); | ||
|
||
const slot = await slotService['validateSlotType'](participant); | ||
|
||
expect(slotService['assignSlot']).toHaveBeenCalled(); | ||
expect(slot.index).toBe(1); | ||
}); | ||
|
||
it('should not assign slot if already assigning', async () => { | ||
slotService['isAssigningSlot'] = true; | ||
|
||
const slot = await slotService['assignSlot'](); | ||
|
||
expect(slot).toEqual(slotService.slot); | ||
}); | ||
|
||
it('should throw error if no more slots are available', async () => { | ||
room.presence.get = jest.fn((callback) => callback(Array(50).fill({}))); | ||
|
||
await expect(slotService['assignSlot']()).resolves.toEqual(null); | ||
}); | ||
}); |
Oops, something went wrong.