Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Fix broadcast pre-recording check (#9834)
Browse files Browse the repository at this point in the history
  • Loading branch information
weeman1337 authored Dec 28, 2022
1 parent c257e13 commit 100b1d5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/voice-broadcast/utils/setUpVoiceBroadcastPreRecording.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ import {
VoiceBroadcastRecordingsStore,
} from "..";

export const setUpVoiceBroadcastPreRecording = (
export const setUpVoiceBroadcastPreRecording = async (
room: Room,
client: MatrixClient,
playbacksStore: VoiceBroadcastPlaybacksStore,
recordingsStore: VoiceBroadcastRecordingsStore,
preRecordingStore: VoiceBroadcastPreRecordingStore,
): VoiceBroadcastPreRecording | null => {
if (!checkVoiceBroadcastPreConditions(room, client, recordingsStore)) {
): Promise<VoiceBroadcastPreRecording | null> => {
if (!(await checkVoiceBroadcastPreConditions(room, client, recordingsStore))) {
return null;
}

Expand Down
48 changes: 29 additions & 19 deletions test/voice-broadcast/utils/setUpVoiceBroadcastPreRecording-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,26 @@ describe("setUpVoiceBroadcastPreRecording", () => {
let playback: VoiceBroadcastPlayback;
let playbacksStore: VoiceBroadcastPlaybacksStore;
let recordingsStore: VoiceBroadcastRecordingsStore;
let preRecording: VoiceBroadcastPreRecording | null;

const itShouldReturnNull = () => {
const itShouldNotCreateAPreRecording = () => {
it("should return null", () => {
expect(
setUpVoiceBroadcastPreRecording(room, client, playbacksStore, recordingsStore, preRecordingStore),
).toBeNull();
expect(checkVoiceBroadcastPreConditions).toHaveBeenCalledWith(room, client, recordingsStore);
expect(preRecording).toBeNull();
});

it("should not create a broadcast pre recording", () => {
expect(preRecordingStore.getCurrent()).toBeNull();
});
};

const setUpPreRecording = async () => {
preRecording = await setUpVoiceBroadcastPreRecording(
room,
client,
playbacksStore,
recordingsStore,
preRecordingStore,
);
};

beforeEach(() => {
Expand All @@ -66,6 +78,7 @@ describe("setUpVoiceBroadcastPreRecording", () => {
client.getUserId()!,
client.getDeviceId()!,
);
preRecording = null;
preRecordingStore = new VoiceBroadcastPreRecordingStore();
playback = new VoiceBroadcastPlayback(infoEvent, client);
jest.spyOn(playback, "pause");
Expand All @@ -74,11 +87,12 @@ describe("setUpVoiceBroadcastPreRecording", () => {
});

describe("when the preconditions fail", () => {
beforeEach(() => {
beforeEach(async () => {
mocked(checkVoiceBroadcastPreConditions).mockResolvedValue(false);
await setUpPreRecording();
});

itShouldReturnNull();
itShouldNotCreateAPreRecording();
});

describe("when the preconditions pass", () => {
Expand All @@ -87,41 +101,37 @@ describe("setUpVoiceBroadcastPreRecording", () => {
});

describe("and there is no user id", () => {
beforeEach(() => {
beforeEach(async () => {
mocked(client.getUserId).mockReturnValue(null);
await setUpPreRecording();
});

itShouldReturnNull();
itShouldNotCreateAPreRecording();
});

describe("and there is no room member", () => {
beforeEach(() => {
beforeEach(async () => {
// check test precondition
expect(room.getMember(userId)).toBeNull();
await setUpPreRecording();
});

itShouldReturnNull();
itShouldNotCreateAPreRecording();
});

describe("and there is a room member and listening to another broadcast", () => {
beforeEach(() => {
playbacksStore.setCurrent(playback);
room.currentState.setStateEvents([mkRoomMemberJoinEvent(userId, roomId)]);
setUpPreRecording();
});

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(playbacksStore.getCurrent()).toBeNull();

expect(checkVoiceBroadcastPreConditions).toHaveBeenCalledWith(room, client, recordingsStore);
expect(result).toBeInstanceOf(VoiceBroadcastPreRecording);
expect(preRecording).toBeInstanceOf(VoiceBroadcastPreRecording);
});
});
});
Expand Down

0 comments on commit 100b1d5

Please sign in to comment.