2022-10-21 07:30:02 +00:00
|
|
|
/*
|
2024-09-09 13:57:16 +00:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2022-10-21 07:30:02 +00:00
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
2024-09-09 13:57:16 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2022-10-21 07:30:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
import { mocked } from "jest-mock";
|
|
|
|
import { MatrixClient, MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
|
|
|
|
|
|
|
|
import {
|
|
|
|
findRoomLiveVoiceBroadcastFromUserAndDevice,
|
|
|
|
VoiceBroadcastInfoEventType,
|
|
|
|
VoiceBroadcastInfoState,
|
2024-10-15 13:57:26 +00:00
|
|
|
} from "../../../../src/voice-broadcast";
|
|
|
|
import { mkEvent, stubClient } from "../../../test-utils";
|
2022-10-21 07:30:02 +00:00
|
|
|
import { mkVoiceBroadcastInfoStateEvent } from "./test-utils";
|
|
|
|
|
|
|
|
describe("findRoomLiveVoiceBroadcastFromUserAndDevice", () => {
|
|
|
|
const roomId = "!room:example.com";
|
|
|
|
let client: MatrixClient;
|
|
|
|
let room: Room;
|
|
|
|
|
|
|
|
const itShouldReturnNull = () => {
|
|
|
|
it("should return null", () => {
|
|
|
|
expect(
|
2023-02-13 17:01:43 +00:00
|
|
|
findRoomLiveVoiceBroadcastFromUserAndDevice(room, client.getUserId()!, client.getDeviceId()!),
|
2022-10-21 07:30:02 +00:00
|
|
|
).toBeNull();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeAll(() => {
|
|
|
|
client = stubClient();
|
2023-02-13 17:01:43 +00:00
|
|
|
room = new Room(roomId, client, client.getUserId()!);
|
2022-10-21 07:30:02 +00:00
|
|
|
jest.spyOn(room.currentState, "getStateEvents");
|
|
|
|
mocked(client.getRoom).mockImplementation((getRoomId: string) => {
|
|
|
|
if (getRoomId === roomId) return room;
|
2023-02-13 17:01:43 +00:00
|
|
|
return null;
|
2022-10-21 07:30:02 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("when there is no info event", () => {
|
|
|
|
itShouldReturnNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("when there is an info event without content", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
room.currentState.setStateEvents([
|
|
|
|
mkEvent({
|
|
|
|
event: true,
|
|
|
|
type: VoiceBroadcastInfoEventType,
|
|
|
|
room: roomId,
|
2023-02-13 17:01:43 +00:00
|
|
|
user: client.getUserId()!,
|
2022-10-21 07:30:02 +00:00
|
|
|
content: {},
|
|
|
|
}),
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
itShouldReturnNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("when there is a stopped info event", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
room.currentState.setStateEvents([
|
|
|
|
mkVoiceBroadcastInfoStateEvent(
|
|
|
|
roomId,
|
|
|
|
VoiceBroadcastInfoState.Stopped,
|
2023-02-13 17:01:43 +00:00
|
|
|
client.getUserId()!,
|
2022-10-21 07:30:02 +00:00
|
|
|
client.getDeviceId(),
|
|
|
|
),
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
itShouldReturnNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("when there is a started info event from another device", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
const event = mkVoiceBroadcastInfoStateEvent(
|
|
|
|
roomId,
|
|
|
|
VoiceBroadcastInfoState.Stopped,
|
2023-02-13 17:01:43 +00:00
|
|
|
client.getUserId()!,
|
2022-10-21 07:30:02 +00:00
|
|
|
"JKL123",
|
|
|
|
);
|
|
|
|
room.currentState.setStateEvents([event]);
|
|
|
|
});
|
|
|
|
|
|
|
|
itShouldReturnNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("when there is a started info event", () => {
|
|
|
|
let event: MatrixEvent;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
event = mkVoiceBroadcastInfoStateEvent(
|
|
|
|
roomId,
|
|
|
|
VoiceBroadcastInfoState.Started,
|
2023-02-13 17:01:43 +00:00
|
|
|
client.getUserId()!,
|
2022-10-21 07:30:02 +00:00
|
|
|
client.getDeviceId(),
|
|
|
|
);
|
|
|
|
room.currentState.setStateEvents([event]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should return this event", () => {
|
|
|
|
expect(room.currentState.getStateEvents).toHaveBeenCalledWith(
|
|
|
|
VoiceBroadcastInfoEventType,
|
2023-02-13 17:01:43 +00:00
|
|
|
client.getUserId()!,
|
2022-10-21 07:30:02 +00:00
|
|
|
);
|
|
|
|
|
2023-02-13 17:01:43 +00:00
|
|
|
expect(findRoomLiveVoiceBroadcastFromUserAndDevice(room, client.getUserId()!, client.getDeviceId()!)).toBe(
|
2022-10-21 07:30:02 +00:00
|
|
|
event,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|