Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MM-57267] Calls: Update post UI #7965

Merged
merged 6 commits into from
May 24, 2024
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
100 changes: 65 additions & 35 deletions app/products/calls/actions/calls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,42 @@ const addFakeCall = (serverUrl: string, channelId: string) => {
const call: Call = {
id: 'call',
sessions: {
a23456abcdefghijklmnopqrs: {sessionId: 'a23456abcdefghijklmnopqrs', userId: 'xohi8cki9787fgiryne716u84o', muted: false, raisedHand: 0},
a12345667890bcdefghijklmn1: {sessionId: 'a12345667890bcdefghijklmn1', userId: 'xohi8cki9787fgiryne716u84o', muted: true, raisedHand: 0},
a12345667890bcdefghijklmn2: {sessionId: 'a12345667890bcdefghijklmn2', userId: 'xohi8cki9787fgiryne716u84o', muted: false, raisedHand: 0},
a12345667890bcdefghijklmn3: {sessionId: 'a12345667890bcdefghijklmn3', userId: 'xohi8cki9787fgiryne716u84o', muted: true, raisedHand: 0},
a12345667890bcdefghijklmn4: {sessionId: 'a12345667890bcdefghijklmn4', userId: 'xohi8cki9787fgiryne716u84o', muted: false, raisedHand: 0},
a12345667890bcdefghijklmn5: {sessionId: 'a12345667890bcdefghijklmn5', userId: 'xohi8cki9787fgiryne716u84o', muted: true, raisedHand: 0},
a23456abcdefghijklmnopqrs: {
sessionId: 'a23456abcdefghijklmnopqrs',
userId: 'xohi8cki9787fgiryne716u84o',
muted: false,
raisedHand: 0,
},
a12345667890bcdefghijklmn1: {
sessionId: 'a12345667890bcdefghijklmn1',
userId: 'xohi8cki9787fgiryne716u84o',
muted: true,
raisedHand: 0,
},
a12345667890bcdefghijklmn2: {
sessionId: 'a12345667890bcdefghijklmn2',
userId: 'xohi8cki9787fgiryne716u84o',
muted: false,
raisedHand: 0,
},
a12345667890bcdefghijklmn3: {
sessionId: 'a12345667890bcdefghijklmn3',
userId: 'xohi8cki9787fgiryne716u84o',
muted: true,
raisedHand: 0,
},
a12345667890bcdefghijklmn4: {
sessionId: 'a12345667890bcdefghijklmn4',
userId: 'xohi8cki9787fgiryne716u84o',
muted: false,
raisedHand: 0,
},
a12345667890bcdefghijklmn5: {
sessionId: 'a12345667890bcdefghijklmn5',
userId: 'xohi8cki9787fgiryne716u84o',
muted: true,
raisedHand: 0,
},
},
channelId,
startTime: (new Date()).getTime(),
Expand Down Expand Up @@ -198,9 +228,9 @@ describe('Actions.Calls', () => {

assert.equal(response!.data, 'channel-id');
assert.equal((result.current[1] as CurrentCall).channelId, 'channel-id');
expect(newConnection).toBeCalled();
expect(newConnection).toHaveBeenCalled();
expect(newConnection.mock.calls[0][1]).toBe('channel-id');
expect(updateThreadFollowing).toBeCalled();
expect(updateThreadFollowing).toHaveBeenCalled();

await act(async () => {
CallsActions.leaveCall();
Expand Down Expand Up @@ -229,7 +259,7 @@ describe('Actions.Calls', () => {
assert.equal(response!.data, 'channel-id');
assert.equal((result.current[1] as CurrentCall | null)?.channelId, 'channel-id');

expect(getConnectionForTesting()!.disconnect).not.toBeCalled();
expect(getConnectionForTesting()!.disconnect).not.toHaveBeenCalled();
const disconnectMock = getConnectionForTesting()!.disconnect;

await act(async () => {
Expand All @@ -239,7 +269,7 @@ describe('Actions.Calls', () => {
myselfLeftCall();
});

expect(disconnectMock).toBeCalled();
expect(disconnectMock).toHaveBeenCalled();
expect(getConnectionForTesting()).toBe(null);
assert.equal((result.current[1] as CurrentCall | null), null);
});
Expand Down Expand Up @@ -270,7 +300,7 @@ describe('Actions.Calls', () => {
CallsActions.muteMyself();
});

expect(getConnectionForTesting()!.mute).toBeCalled();
expect(getConnectionForTesting()!.mute).toHaveBeenCalled();

await act(async () => {
CallsActions.leaveCall();
Expand Down Expand Up @@ -303,7 +333,7 @@ describe('Actions.Calls', () => {
CallsActions.unmuteMyself();
});

expect(getConnectionForTesting()!.unmute).toBeCalled();
expect(getConnectionForTesting()!.unmute).toHaveBeenCalled();

await act(async () => {
CallsActions.leaveCall();
Expand All @@ -319,7 +349,7 @@ describe('Actions.Calls', () => {
await act(async () => {
await CallsActions.loadCalls('server1', 'userId1');
});
expect(mockClient.getCalls).toBeCalled();
expect(mockClient.getCalls).toHaveBeenCalled();
assert.equal((result.current[0] as CallsState).calls['channel-1'].channelId, 'channel-1');
assert.equal((result.current[0] as CallsState).enabled['channel-1'], true);
assert.equal((result.current[1] as ChannelsWithCalls)['channel-1'], true);
Expand Down Expand Up @@ -347,7 +377,7 @@ describe('Actions.Calls', () => {
await act(async () => {
await CallsActions.loadCalls('server1', 'userId1');
});
expect(mockClient.getCalls).toBeCalled();
expect(mockClient.getCalls).toHaveBeenCalled();
assert.deepEqual((result.current[0] as CallsState), expectedCallsState);
assert.deepEqual((result.current[1] as ChannelsWithCalls), {});
assert.equal((result.current[2] as CurrentCall | null), null);
Expand All @@ -362,7 +392,7 @@ describe('Actions.Calls', () => {
await act(async () => {
await CallsActions.loadConfig('server1');
});
expect(mockClient.getCallsConfig).toBeCalledWith();
expect(mockClient.getCallsConfig).toHaveBeenCalledWith();
assert.equal(result.current.DefaultEnabled, true);
assert.equal(result.current.AllowEnableCalls, true);
});
Expand All @@ -374,7 +404,7 @@ describe('Actions.Calls', () => {
await act(async () => {
await CallsActions.enableChannelCalls('server1', 'channel-1', true);
});
expect(mockClient.enableChannelCalls).toBeCalledWith('channel-1', true);
expect(mockClient.enableChannelCalls).toHaveBeenCalledWith('channel-1', true);
assert.equal(result.current.enabled['channel-1'], true);
});

Expand All @@ -385,13 +415,13 @@ describe('Actions.Calls', () => {
await act(async () => {
await CallsActions.enableChannelCalls('server1', 'channel-1', true);
});
expect(mockClient.enableChannelCalls).toBeCalledWith('channel-1', true);
expect(mockClient.enableChannelCalls).toHaveBeenCalledWith('channel-1', true);
assert.equal(result.current.enabled['channel-1'], true);
mockClient.enableChannelCalls.mockReturnValueOnce({enabled: false});
await act(async () => {
await CallsActions.enableChannelCalls('server1', 'channel-1', false);
});
expect(mockClient.enableChannelCalls).toBeCalledWith('channel-1', false);
expect(mockClient.enableChannelCalls).toHaveBeenCalledWith('channel-1', false);
assert.equal(result.current.enabled['channel-1'], false);
});

Expand All @@ -400,26 +430,26 @@ describe('Actions.Calls', () => {
await CallsActions.startCallRecording('server1', 'channel-id');
});

expect(mockClient.startCallRecording).toBeCalledWith('channel-id');
expect(needsRecordingErrorAlert).toBeCalled();
expect(mockClient.startCallRecording).toHaveBeenCalledWith('channel-id');
expect(needsRecordingErrorAlert).toHaveBeenCalled();
});

it('stopCallRecording', async () => {
await act(async () => {
await CallsActions.stopCallRecording('server1', 'channel-id');
});

expect(mockClient.stopCallRecording).toBeCalledWith('channel-id');
expect(needsRecordingErrorAlert).toBeCalled();
expect(needsRecordingWillBePostedAlert).toBeCalled();
expect(mockClient.stopCallRecording).toHaveBeenCalledWith('channel-id');
expect(needsRecordingErrorAlert).toHaveBeenCalled();
expect(needsRecordingWillBePostedAlert).toHaveBeenCalled();
});

it('dismissIncomingCall', async () => {
await act(async () => {
await CallsActions.dismissIncomingCall('server1', 'channel-id');
});

expect(mockClient.dismissCall).toBeCalledWith('channel-id');
expect(mockClient.dismissCall).toHaveBeenCalledWith('channel-id');
});

it('userLeftChannelErr', async () => {
Expand All @@ -446,20 +476,20 @@ describe('Actions.Calls', () => {

assert.equal(response!.data, 'channel-id');
assert.equal((result.current[1] as CurrentCall).channelId, 'channel-id');
expect(newConnection).toBeCalled();
expect(newConnection).toHaveBeenCalled();
expect(newConnection.mock.calls[0][1]).toBe('channel-id');
expect(updateThreadFollowing).toBeCalled();
expect(updateThreadFollowing).toHaveBeenCalled();

await act(async () => {
CallsActions.leaveCall(userLeftChannelErr);
});

expect(intl.formatMessage).toBeCalledWith({
expect(intl.formatMessage).toHaveBeenCalledWith({
id: 'mobile.calls_user_left_channel_error_title',
defaultMessage: 'You left the channel',
});

expect(intl.formatMessage).toBeCalledWith({
expect(intl.formatMessage).toHaveBeenCalledWith({
id: 'mobile.calls_user_left_channel_error_message',
defaultMessage: 'You have left the channel, and have been disconnected from the call.',
});
Expand Down Expand Up @@ -489,20 +519,20 @@ describe('Actions.Calls', () => {

assert.equal(response!.data, 'channel-id');
assert.equal((result.current[1] as CurrentCall).channelId, 'channel-id');
expect(newConnection).toBeCalled();
expect(newConnection).toHaveBeenCalled();
expect(newConnection.mock.calls[0][1]).toBe('channel-id');
expect(updateThreadFollowing).toBeCalled();
expect(updateThreadFollowing).toHaveBeenCalled();

await act(async () => {
CallsActions.leaveCall(userRemovedFromChannelErr);
});

expect(intl.formatMessage).toBeCalledWith({
expect(intl.formatMessage).toHaveBeenCalledWith({
id: 'mobile.calls_user_removed_from_channel_error_title',
defaultMessage: 'You were removed from channel',
});

expect(intl.formatMessage).toBeCalledWith({
expect(intl.formatMessage).toHaveBeenCalledWith({
id: 'mobile.calls_user_removed_from_channel_error_message',
defaultMessage: 'You have been removed from the channel, and have been disconnected from the call.',
});
Expand Down Expand Up @@ -532,14 +562,14 @@ describe('Actions.Calls', () => {

assert.equal(response!.data, 'channel-id');
assert.equal((result.current[1] as CurrentCall).channelId, 'channel-id');
expect(newConnection).toBeCalled();
expect(newConnection).toHaveBeenCalled();
expect(newConnection.mock.calls[0][1]).toBe('channel-id');
expect(updateThreadFollowing).toBeCalled();
expect(updateThreadFollowing).toHaveBeenCalled();

await act(async () => {
CallsActions.leaveCall(new Error('generic error'));
});

expect(errorAlert).toBeCalled();
expect(errorAlert).toHaveBeenCalled();
});
});
2 changes: 1 addition & 1 deletion app/products/calls/actions/calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ export const canEndCall = async (serverUrl: string, channelId: string) => {
return false;
}

return isSystemAdmin(currentUser.roles) || currentUser.id === call.ownerId;
return isSystemAdmin(currentUser.roles) || currentUser.id === call.hostId;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a breaking change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, we've sent hostId since 2022-11.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, running this against a previous plugin would make it fail because the backend check would be on the owner ID. Not overly worried though.

};

export const getEndCallMessage = async (serverUrl: string, channelId: string, currentUserId: string, intl: IntlShape) => {
Expand Down
Loading
Loading