1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-07 23:02:56 +03:00

TS strict mode compliance in the call / groupcall code (#2805)

* TS strict mode compliance in the call / groupcall code

* Also the test

* Fix initOpponentCrypto

to not panic if it doesn't actually need to init crypto
This commit is contained in:
David Baker
2022-10-26 11:45:03 +01:00
committed by GitHub
parent 450ff00c3e
commit c374ba2367
9 changed files with 186 additions and 153 deletions

View File

@@ -99,7 +99,7 @@ describe("CallEventHandler", () => {
expect(callEventHandler.callEventBuffer.length).toBe(2);
expect(callEventHandler.nextSeqByCall.get("123")).toBe(2);
expect(callEventHandler.toDeviceEventBuffers.get("123").length).toBe(1);
expect(callEventHandler.toDeviceEventBuffers.get("123")?.length).toBe(1);
const event4 = new MatrixEvent({
type: EventType.CallCandidates,
@@ -112,7 +112,7 @@ describe("CallEventHandler", () => {
expect(callEventHandler.callEventBuffer.length).toBe(2);
expect(callEventHandler.nextSeqByCall.get("123")).toBe(2);
expect(callEventHandler.toDeviceEventBuffers.get("123").length).toBe(2);
expect(callEventHandler.toDeviceEventBuffers.get("123")?.length).toBe(2);
const event5 = new MatrixEvent({
type: EventType.CallCandidates,
@@ -125,7 +125,7 @@ describe("CallEventHandler", () => {
expect(callEventHandler.callEventBuffer.length).toBe(5);
expect(callEventHandler.nextSeqByCall.get("123")).toBe(5);
expect(callEventHandler.toDeviceEventBuffers.get("123").length).toBe(0);
expect(callEventHandler.toDeviceEventBuffers.get("123")?.length).toBe(0);
});
it("should ignore a call if invite & hangup come within a single sync", () => {
@@ -161,7 +161,7 @@ describe("CallEventHandler", () => {
it("should ignore non-call events", async () => {
// @ts-ignore Mock handleCallEvent is private
jest.spyOn(client.callEventHandler, "handleCallEvent");
jest.spyOn(client, "checkTurnServers").mockReturnValue(undefined);
jest.spyOn(client, "checkTurnServers").mockReturnValue(Promise.resolve(true));
const room = new Room("!room:id", client, "@user:id");
const timelineData: IRoomTimelineData = { timeline: new EventTimeline(new EventTimelineSet(room, {})) };
@@ -186,10 +186,10 @@ describe("CallEventHandler", () => {
let room: Room;
beforeEach(() => {
room = new Room("!room:id", client, client.getUserId());
room = new Room("!room:id", client, client.getUserId()!);
timelineData = { timeline: new EventTimeline(new EventTimelineSet(room, {})) };
jest.spyOn(client, "checkTurnServers").mockReturnValue(undefined);
jest.spyOn(client, "checkTurnServers").mockReturnValue(Promise.resolve(true));
jest.spyOn(client, "getRoom").mockReturnValue(room);
jest.spyOn(room, "getMember").mockReturnValue({ user_id: client.getUserId() } as unknown as RoomMember);
@@ -246,10 +246,10 @@ describe("CallEventHandler", () => {
await sync();
expect(incomingCallListener).toHaveBeenCalled();
expect(call.groupCallId).toBe(GROUP_CALL_ID);
expect(call!.groupCallId).toBe(GROUP_CALL_ID);
// @ts-ignore Mock opponentDeviceId is private
expect(call.opponentDeviceId).toBe(DEVICE_ID);
expect(call.getOpponentSessionId()).toBe(SESSION_ID);
expect(call!.getOpponentSessionId()).toBe(SESSION_ID);
// @ts-ignore Mock onIncomingCall is private
expect(groupCall.onIncomingCall).toHaveBeenCalledWith(call);