Skip to content

Commit

Permalink
fix: add tests
Browse files Browse the repository at this point in the history
Signed-off-by: DorraJaouad <[email protected]>
  • Loading branch information
DorraJaouad committed Nov 6, 2024
1 parent 634c44f commit f02333a
Showing 1 changed file with 57 additions and 17 deletions.
74 changes: 57 additions & 17 deletions src/store/participantsStore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ describe('participantsStore', () => {
const flags = PARTICIPANT.CALL_FLAG.WITH_AUDIO | PARTICIPANT.CALL_FLAG.WITH_VIDEO

beforeEach(async () => {
jest.useFakeTimers()
testStoreConfig.getters.conversation = () => jest.fn().mockReturnValue({
token: TOKEN,
type: 3,
Expand All @@ -555,8 +556,7 @@ describe('participantsStore', () => {
},
})

// The requested flags and the actual flags can be different if some
// media device is not available.
// Setup joinCall and leaveCall mock behavior
joinCall.mockResolvedValue(actualFlags)
leaveCall.mockResolvedValue()

Expand All @@ -572,30 +572,70 @@ describe('participantsStore', () => {
})
})

test('joins call', async () => {
// Assert
afterEach(() => {
jest.clearAllTimers()
})

const assertInitialCallState = () => {
expect(joinCall).toHaveBeenCalledWith(TOKEN, flags, false, false)
// Mock the signaling event
EventBus.emit('signaling-join-call')
EventBus.emit('signaling-join-call', [TOKEN, actualFlags])
expect(store.getters.isInCall(TOKEN)).toBe(true)
expect(store.getters.isConnecting(TOKEN)).toBe(true)
expect(store.getters.participantsList(TOKEN)).toStrictEqual([
{
attendeeId: 1,
sessionId: 'session-id-1',
inCall: actualFlags,
participantType: PARTICIPANT.TYPE.USER,
},
])
expect(store.getters.participantsList(TOKEN)).toStrictEqual([{
attendeeId: 1,
sessionId: 'session-id-1',
inCall: actualFlags,
participantType: PARTICIPANT.TYPE.USER,
}])
}

const finishConnectingWithUsers = (participants) => {
EventBus.emit('signaling-users-in-room', [participants])
expect(store.getters.isInCall(TOKEN)).toBe(true)
expect(store.getters.isConnecting(TOKEN)).toBe(false)
}

// Finished connecting to the call
EventBus.emit('signaling-users-in-room', [[{
const emitFailureAndAssert = (reason) => {
EventBus.emit('signaling-join-call-failed', [TOKEN, reason])
expect(store.getters.isInCall(TOKEN)).toBe(false)
expect(store.getters.isConnecting(TOKEN)).toBe(false)
}

test('joins call with internal signaling', async () => {
assertInitialCallState()
finishConnectingWithUsers([{
attendeeId: 1,
sessionId: 'session-id-1',
inCall: actualFlags,
participantType: PARTICIPANT.TYPE.USER,
}])
})

test('joins call with external signaling', async () => {
assertInitialCallState()
EventBus.emit('signaling-users-changed', [[{
attendeeId: 1,
nextcloudSessionId: 'session-id-1',
inCall: actualFlags,
participantType: PARTICIPANT.TYPE.USER,
}]])
expect(store.getters.isInCall(TOKEN)).toBe(true)
expect(store.getters.isConnecting(TOKEN)).toBe(false)
})

test('joins call but it fails', async () => {
assertInitialCallState()
emitFailureAndAssert('error reason')
})

test('joins call but it does not receive participants list', async () => {
assertInitialCallState()
// No other signaling event, simulates a missing participant list
expect(store.getters.isInCall(TOKEN)).toBe(true)
expect(store.getters.isConnecting(TOKEN)).toBe(true)

// Trigger fallback after delay
jest.advanceTimersByTime(10000)
expect(store.getters.isInCall(TOKEN)).toBe(true)
expect(store.getters.isConnecting(TOKEN)).toBe(false)
})
Expand Down Expand Up @@ -913,7 +953,7 @@ describe('participantsStore', () => {
flags,
silent: false,
})
EventBus.emit('signaling-join-call')
EventBus.emit('signaling-join-call', [TOKEN, flags])
expect(store.getters.isInCall(TOKEN)).toBe(true)

leaveConversation.mockResolvedValue()
Expand Down

0 comments on commit f02333a

Please sign in to comment.