Fix broadcast pre-recording check (#9834)

pull/28788/head^2
Michael Weimann 2022-12-28 16:13:37 +01:00 committed by GitHub
parent c257e137aa
commit 100b1d5aa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 22 deletions

View File

@ -24,14 +24,14 @@ import {
VoiceBroadcastRecordingsStore, VoiceBroadcastRecordingsStore,
} from ".."; } from "..";
export const setUpVoiceBroadcastPreRecording = ( export const setUpVoiceBroadcastPreRecording = async (
room: Room, room: Room,
client: MatrixClient, client: MatrixClient,
playbacksStore: VoiceBroadcastPlaybacksStore, playbacksStore: VoiceBroadcastPlaybacksStore,
recordingsStore: VoiceBroadcastRecordingsStore, recordingsStore: VoiceBroadcastRecordingsStore,
preRecordingStore: VoiceBroadcastPreRecordingStore, preRecordingStore: VoiceBroadcastPreRecordingStore,
): VoiceBroadcastPreRecording | null => { ): Promise<VoiceBroadcastPreRecording | null> => {
if (!checkVoiceBroadcastPreConditions(room, client, recordingsStore)) { if (!(await checkVoiceBroadcastPreConditions(room, client, recordingsStore))) {
return null; return null;
} }

View File

@ -42,14 +42,26 @@ describe("setUpVoiceBroadcastPreRecording", () => {
let playback: VoiceBroadcastPlayback; let playback: VoiceBroadcastPlayback;
let playbacksStore: VoiceBroadcastPlaybacksStore; let playbacksStore: VoiceBroadcastPlaybacksStore;
let recordingsStore: VoiceBroadcastRecordingsStore; let recordingsStore: VoiceBroadcastRecordingsStore;
let preRecording: VoiceBroadcastPreRecording | null;
const itShouldReturnNull = () => { const itShouldNotCreateAPreRecording = () => {
it("should return null", () => { it("should return null", () => {
expect( expect(preRecording).toBeNull();
setUpVoiceBroadcastPreRecording(room, client, playbacksStore, recordingsStore, preRecordingStore),
).toBeNull();
expect(checkVoiceBroadcastPreConditions).toHaveBeenCalledWith(room, client, recordingsStore);
}); });
it("should not create a broadcast pre recording", () => {
expect(preRecordingStore.getCurrent()).toBeNull();
});
};
const setUpPreRecording = async () => {
preRecording = await setUpVoiceBroadcastPreRecording(
room,
client,
playbacksStore,
recordingsStore,
preRecordingStore,
);
}; };
beforeEach(() => { beforeEach(() => {
@ -66,6 +78,7 @@ describe("setUpVoiceBroadcastPreRecording", () => {
client.getUserId()!, client.getUserId()!,
client.getDeviceId()!, client.getDeviceId()!,
); );
preRecording = null;
preRecordingStore = new VoiceBroadcastPreRecordingStore(); preRecordingStore = new VoiceBroadcastPreRecordingStore();
playback = new VoiceBroadcastPlayback(infoEvent, client); playback = new VoiceBroadcastPlayback(infoEvent, client);
jest.spyOn(playback, "pause"); jest.spyOn(playback, "pause");
@ -74,11 +87,12 @@ describe("setUpVoiceBroadcastPreRecording", () => {
}); });
describe("when the preconditions fail", () => { describe("when the preconditions fail", () => {
beforeEach(() => { beforeEach(async () => {
mocked(checkVoiceBroadcastPreConditions).mockResolvedValue(false); mocked(checkVoiceBroadcastPreConditions).mockResolvedValue(false);
await setUpPreRecording();
}); });
itShouldReturnNull(); itShouldNotCreateAPreRecording();
}); });
describe("when the preconditions pass", () => { describe("when the preconditions pass", () => {
@ -87,41 +101,37 @@ describe("setUpVoiceBroadcastPreRecording", () => {
}); });
describe("and there is no user id", () => { describe("and there is no user id", () => {
beforeEach(() => { beforeEach(async () => {
mocked(client.getUserId).mockReturnValue(null); mocked(client.getUserId).mockReturnValue(null);
await setUpPreRecording();
}); });
itShouldReturnNull(); itShouldNotCreateAPreRecording();
}); });
describe("and there is no room member", () => { describe("and there is no room member", () => {
beforeEach(() => { beforeEach(async () => {
// check test precondition // check test precondition
expect(room.getMember(userId)).toBeNull(); expect(room.getMember(userId)).toBeNull();
await setUpPreRecording();
}); });
itShouldReturnNull(); itShouldNotCreateAPreRecording();
}); });
describe("and there is a room member and listening to another broadcast", () => { describe("and there is a room member and listening to another broadcast", () => {
beforeEach(() => { beforeEach(() => {
playbacksStore.setCurrent(playback); playbacksStore.setCurrent(playback);
room.currentState.setStateEvents([mkRoomMemberJoinEvent(userId, roomId)]); room.currentState.setStateEvents([mkRoomMemberJoinEvent(userId, roomId)]);
setUpPreRecording();
}); });
it("should pause the current playback and create a voice broadcast pre-recording", () => { it("should pause the current playback and create a voice broadcast pre-recording", () => {
const result = setUpVoiceBroadcastPreRecording(
room,
client,
playbacksStore,
recordingsStore,
preRecordingStore,
);
expect(playback.pause).toHaveBeenCalled(); expect(playback.pause).toHaveBeenCalled();
expect(playbacksStore.getCurrent()).toBeNull(); expect(playbacksStore.getCurrent()).toBeNull();
expect(checkVoiceBroadcastPreConditions).toHaveBeenCalledWith(room, client, recordingsStore); expect(checkVoiceBroadcastPreConditions).toHaveBeenCalledWith(room, client, recordingsStore);
expect(result).toBeInstanceOf(VoiceBroadcastPreRecording); expect(preRecording).toBeInstanceOf(VoiceBroadcastPreRecording);
}); });
}); });
}); });