Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions app/containers/NewMediaCall/VoipCallLifecycle.integration.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
// - Hang up (UI endCall and MediaSessionInstance.endCall ringing/active branches)
// - In-call controls (mute, hold, trackStateChange sync)
//
// Seam: @rocket.chat/media-signaling is mocked at the SDK boundary. Everything
// between the SDK and the UI — MediaSessionInstance, useCallStore, NewMediaCall,
// CallView — runs as real code.
// Seam: @rocket.chat/media-signaling is mocked at the SDK boundary (see block
// comment on the jest.mock below). Everything between that mock and the UI —
// MediaSessionInstance, useCallStore, NewMediaCall, CallView — runs as real code.

import React from 'react';
import { act, fireEvent, render } from '@testing-library/react-native';
Expand Down Expand Up @@ -184,6 +184,11 @@ function mockCallEmitter() {
}

// ─── Media-signaling mock ─────────────────────────────────────────────────────
//
// @rocket.chat/media-signaling (WebRTC stack) is fully mocked here. These tests
// exercise signaling orchestration, Zustand, and navigation — not real peer
// connections, ICE, or media tracks. Catching regressions in WebRTC-specific
// behavior still requires device or E2E coverage outside Jest.

type MockMediaSignalingSession = {
userId: string;
Expand Down Expand Up @@ -647,15 +652,17 @@ describe('VoIP call lifecycle (integration)', () => {
expect(useCallStore.getState().call).toBeNull();
});

it('B3: MediaSessionInstance.endCall during ringing → same cleanup (reject branch)', () => {
it('B3: MediaSessionInstance.endCall during ringing → reject (not hangup) + RNCallKeep cleanup', () => {
const session = createdSessions[createdSessions.length - 1];
const ringingCall = makeCall({ callId: 'ringing-1', state: 'ringing' });
const ringingCall = makeCall({ callId: 'ringing-1' });
session.getCallData.mockReturnValue(ringingCall);

act(() => {
mediaSessionInstance.endCall('ringing-1');
});

expect(ringingCall.reject).toHaveBeenCalled();
expect(ringingCall.hangup).not.toHaveBeenCalled();
expect(RNCallKeep.endCall as jest.Mock).toHaveBeenCalledWith('ringing-1');
expect(useCallStore.getState().call).toBeNull();
});
Expand Down
68 changes: 68 additions & 0 deletions app/sagas/__tests__/videoConf.voipBlock.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
jest.mock('../../lib/services/voip/voipBlocksIncomingVideoconf', () => ({
voipBlocksIncomingVideoconf: jest.fn(() => false)
}));

import { applyMiddleware, createStore } from 'redux';
import createSagaMiddleware from 'redux-saga';

import { handleVideoConfIncomingWebsocketMessages } from '../../actions/videoConf';
import reducers from '../../reducers';
import videoConfRootSaga from '../videoConf';
import { voipBlocksIncomingVideoconf } from '../../lib/services/voip/voipBlocksIncomingVideoconf';

/** Drains pending saga microtasks (takeEvery → call(onDirectCall) completes synchronously today). */
async function flushSagaMicrotasks(): Promise<void> {
await Promise.resolve();
await Promise.resolve();
}

describe('videoConf saga — VoIP / videoconf lock', () => {
// Mirrors the first DDP arg destructured at app/lib/methods/subscriptions/rooms.ts
// and dispatched as `{ action, params }` into handleVideoConfIncomingWebsocketMessages.
const envelope = {
action: 'call' as const,
params: { callId: 'vc-1', uid: 'user-b', rid: 'room-1' }
};

beforeEach(() => {
jest.mocked(voipBlocksIncomingVideoconf).mockReset();
jest.mocked(voipBlocksIncomingVideoconf).mockReturnValue(false);
});

function setupStoreWithVideoConfSaga() {
const sagaMiddleware = createSagaMiddleware();
const store = createStore(reducers, applyMiddleware(sagaMiddleware));
sagaMiddleware.run(videoConfRootSaga);
return store;
}

it('short-circuits incoming direct videoconf when voipBlocksIncomingVideoconf returns true', async () => {
jest.mocked(voipBlocksIncomingVideoconf).mockReturnValue(true);

const store = setupStoreWithVideoConfSaga();
const callsBefore = store.getState().videoConf.calls;

store.dispatch(handleVideoConfIncomingWebsocketMessages({ action: envelope, params: undefined }));
await flushSagaMicrotasks();

expect(voipBlocksIncomingVideoconf).toHaveBeenCalled();
expect(store.getState().videoConf.calls).toBe(callsBefore);
expect(store.getState().videoConf.calls).toHaveLength(0);
});

it('handles incoming direct videoconf when VoIP does not block', async () => {
const store = setupStoreWithVideoConfSaga();

store.dispatch(handleVideoConfIncomingWebsocketMessages({ action: envelope, params: undefined }));
await flushSagaMicrotasks();

expect(voipBlocksIncomingVideoconf).toHaveBeenCalled();
expect(store.getState().videoConf.calls).toHaveLength(1);
expect(store.getState().videoConf.calls[0]).toMatchObject({
callId: 'vc-1',
uid: 'user-b',
rid: 'room-1',
action: 'call'
});
});
});
Loading