Skip to content

Commit 05f6cb7

Browse files
committed
fix(voip): correct event name and clean up unused test code
- Change performSetMutedCallAction → didPerformSetMutedCallAction in MediaCallEvents.ts so CallKit mute events actually fire - Remove unused imports/variables from MediaCallEvents.ios.test.ts (DeviceEventEmitter, RNCallKeep, DEEP_LINKING, VoipPayload, NativeVoipModule, getInitialMediaCallEvents, mockDispatch, etc.) - Remove unused getMuteHandler helper from MediaCallEvents.test.ts
1 parent 0f40eb7 commit 05f6cb7

File tree

3 files changed

+10
-53
lines changed

3 files changed

+10
-53
lines changed

app/lib/services/voip/MediaCallEvents.ios.test.ts

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,49 @@
11
/**
22
* @jest-environment node
33
*
4-
* iOS-only mute tests: requires isIOS = true so performSetMutedCallAction listener is registered.
4+
* iOS-only mute tests: requires isIOS = true so didPerformSetMutedCallAction listener is registered.
55
*/
6-
import { DeviceEventEmitter } from 'react-native';
7-
import RNCallKeep from 'react-native-callkeep';
8-
9-
import { DEEP_LINKING } from '../../../actions/actionsTypes';
10-
import type { VoipPayload } from '../../../definitions/Voip';
11-
import NativeVoipModule from '../../native/NativeVoip';
12-
import { getInitialMediaCallEvents, setupMediaCallEvents } from './MediaCallEvents';
6+
import { setupMediaCallEvents } from './MediaCallEvents';
137
import { useCallStore } from './useCallStore';
148

15-
const mockDispatch = jest.fn();
16-
const mockSetNativeAcceptedCallId = jest.fn();
179
const mockAddEventListener = jest.fn();
18-
const mockRNCallKeepClearInitialEvents = jest.fn();
19-
const mockSetCurrentCallActive = jest.fn();
2010

2111
jest.mock('../../methods/helpers', () => ({
2212
...jest.requireActual('../../methods/helpers'),
2313
isIOS: true
2414
}));
2515

26-
jest.mock('../../store', () => ({
27-
__esModule: true,
28-
default: {
29-
dispatch: (...args: unknown[]) => mockDispatch(...args)
30-
}
31-
}));
32-
3316
jest.mock('./useCallStore', () => ({
3417
useCallStore: {
3518
getState: jest.fn()
3619
}
3720
}));
3821

39-
jest.mock('../../native/NativeVoip', () => ({
40-
__esModule: true,
41-
default: {
42-
clearInitialEvents: jest.fn(),
43-
getInitialEvents: jest.fn(() => null)
44-
}
45-
}));
46-
4722
jest.mock('react-native-callkeep', () => ({
4823
__esModule: true,
4924
default: {
5025
addEventListener: (...args: unknown[]) => mockAddEventListener(...args),
51-
clearInitialEvents: (...args: unknown[]) => mockRNCallKeepClearInitialEvents(...args),
52-
setCurrentCallActive: (...args: unknown[]) => mockSetCurrentCallActive(...args),
26+
clearInitialEvents: jest.fn(),
27+
setCurrentCallActive: jest.fn(),
5328
getInitialEvents: jest.fn(() => Promise.resolve([]))
5429
}
5530
}));
5631

57-
jest.mock('./MediaSessionInstance', () => ({
58-
mediaSessionInstance: {
59-
endCall: jest.fn()
60-
}
61-
}));
62-
63-
jest.mock('../restApi', () => ({
64-
registerPushToken: jest.fn(() => Promise.resolve())
65-
}));
66-
6732
const activeCallBase = {
6833
call: {} as object,
6934
callId: 'uuid-1',
7035
nativeAcceptedCallId: null as string | null
7136
};
7237

7338
function getMuteHandler(): (payload: { muted: boolean; callUUID: string }) => void {
74-
const call = mockAddEventListener.mock.calls.find(([name]) => name === 'performSetMutedCallAction');
39+
const call = mockAddEventListener.mock.calls.find(([name]) => name === 'didPerformSetMutedCallAction');
7540
if (!call) {
76-
throw new Error('performSetMutedCallAction listener not registered');
41+
throw new Error('didPerformSetMutedCallAction listener not registered');
7742
}
7843
return call[1] as (payload: { muted: boolean; callUUID: string }) => void;
7944
}
8045

81-
describe('setupMediaCallEvents — performSetMutedCallAction (iOS)', () => {
46+
describe('setupMediaCallEvents — didPerformSetMutedCallAction (iOS)', () => {
8247
const toggleMute = jest.fn();
8348
const getState = useCallStore.getState as jest.Mock;
8449

@@ -89,9 +54,9 @@ describe('setupMediaCallEvents — performSetMutedCallAction (iOS)', () => {
8954
getState.mockReturnValue({ ...activeCallBase, isMuted: false, toggleMute });
9055
});
9156

92-
it('registers performSetMutedCallAction via RNCallKeep.addEventListener', () => {
57+
it('registers didPerformSetMutedCallAction via RNCallKeep.addEventListener', () => {
9358
setupMediaCallEvents();
94-
expect(mockAddEventListener).toHaveBeenCalledWith('performSetMutedCallAction', expect.any(Function));
59+
expect(mockAddEventListener).toHaveBeenCalledWith('didPerformSetMutedCallAction', expect.any(Function));
9560
});
9661

9762
it('calls toggleMute when muted state differs from OS and UUIDs match', () => {

app/lib/services/voip/MediaCallEvents.test.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,6 @@ const activeCallBase = {
8787
nativeAcceptedCallId: null as string | null
8888
};
8989

90-
function getMuteHandler(): (payload: { muted: boolean; callUUID: string }) => void {
91-
const call = mockAddEventListener.mock.calls.find(([name]) => name === 'performSetMutedCallAction');
92-
if (!call) {
93-
throw new Error('performSetMutedCallAction listener not registered');
94-
}
95-
return call[1] as (payload: { muted: boolean; callUUID: string }) => void;
96-
}
97-
9890
describe('MediaCallEvents cross-server accept (slice 3)', () => {
9991
const getState = useCallStore.getState as jest.Mock;
10092

app/lib/services/voip/MediaCallEvents.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const setupMediaCallEvents = (): (() => void) => {
9090
);
9191

9292
subscriptions.push(
93-
RNCallKeep.addEventListener('performSetMutedCallAction', ({ muted, callUUID }) => {
93+
RNCallKeep.addEventListener('didPerformSetMutedCallAction', ({ muted, callUUID }) => {
9494
const { call, callId, nativeAcceptedCallId, toggleMute, isMuted } = useCallStore.getState();
9595
const eventUuid = callUUID.toLowerCase();
9696
const activeUuid = (callId ?? nativeAcceptedCallId ?? '').toLowerCase();

0 commit comments

Comments
 (0)