diff --git a/spec/unit/matrix-client.spec.ts b/spec/unit/matrix-client.spec.ts index 2b8faf506..98c496d76 100644 --- a/spec/unit/matrix-client.spec.ts +++ b/spec/unit/matrix-client.spec.ts @@ -1714,4 +1714,39 @@ describe("MatrixClient", function() { expect(newSourceRoom._state.get(PolicyScope.User)?.[eventId]).toBeFalsy(); }); }); + + describe("using E2EE in group calls", () => { + const opts = { + baseUrl: "https://my.home.server", + idBaseUrl: identityServerUrl, + accessToken: "my.access.token", + store: store, + scheduler: scheduler, + userId: userId, + }; + + it("enables E2EE by default", () => { + const client = new MatrixClient(opts); + + expect(client.getUseE2eForGroupCall()).toBe(true); + }); + + it("enables E2EE when enabled explicitly", () => { + const client = new MatrixClient({ + useE2eForGroupCall: true, + ...opts, + }); + + expect(client.getUseE2eForGroupCall()).toBe(true); + }); + + it("disables E2EE if disabled explicitly", () => { + const client = new MatrixClient({ + useE2eForGroupCall: false, + ...opts, + }); + + expect(client.getUseE2eForGroupCall()).toBe(false); + }); + }); }); diff --git a/spec/unit/webrtc/groupCall.spec.ts b/spec/unit/webrtc/groupCall.spec.ts index 1c2508766..cfc70cfa4 100644 --- a/spec/unit/webrtc/groupCall.spec.ts +++ b/spec/unit/webrtc/groupCall.spec.ts @@ -1118,4 +1118,93 @@ describe('Group Call', function() { expect(onActiveSpeakerEvent).toHaveBeenCalledWith(FAKE_USER_ID_3); }); }); + + describe("creating group calls", () => { + let client: MatrixClient; + + beforeEach(() => { + client = new MatrixClient({ + baseUrl: "base_url", + request: (() => {}) as any, // NOP + }); + + jest.spyOn(client, "sendStateEvent").mockResolvedValue({} as any); + }); + + afterEach(() => { + client.stopClient(); + }); + + it("throws when there already is a call", async () => { + jest.spyOn(client, "getRoom").mockReturnValue(new Room("room_id", client, "my_user_id")); + + await client.createGroupCall( + "room_id", + GroupCallType.Video, + false, + GroupCallIntent.Prompt, + ); + + await expect(client.createGroupCall( + "room_id", + GroupCallType.Video, + false, + GroupCallIntent.Prompt, + )).rejects.toThrow("room_id already has an existing group call"); + }); + + it("throws if the room doesn't exist", async () => { + await expect(client.createGroupCall( + "room_id", + GroupCallType.Video, + false, + GroupCallIntent.Prompt, + )).rejects.toThrow("Cannot find room room_id"); + }); + + describe("correctly passes parameters", () => { + beforeEach(() => { + jest.spyOn(client, "getRoom").mockReturnValue(new Room("room_id", client, "my_user_id")); + }); + + it("correctly passes voice ptt room call", async () => { + const groupCall = await client.createGroupCall( + "room_id", + GroupCallType.Voice, + true, + GroupCallIntent.Room, + ); + + expect(groupCall.type).toBe(GroupCallType.Voice); + expect(groupCall.isPtt).toBe(true); + expect(groupCall.intent).toBe(GroupCallIntent.Room); + }); + + it("correctly passes voice ringing call", async () => { + const groupCall = await client.createGroupCall( + "room_id", + GroupCallType.Voice, + false, + GroupCallIntent.Ring, + ); + + expect(groupCall.type).toBe(GroupCallType.Voice); + expect(groupCall.isPtt).toBe(false); + expect(groupCall.intent).toBe(GroupCallIntent.Ring); + }); + + it("correctly passes video prompt call", async () => { + const groupCall = await client.createGroupCall( + "room_id", + GroupCallType.Video, + false, + GroupCallIntent.Prompt, + ); + + expect(groupCall.type).toBe(GroupCallType.Video); + expect(groupCall.isPtt).toBe(false); + expect(groupCall.intent).toBe(GroupCallIntent.Prompt); + }); + }); + }); });