Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
virgilchiriac committed Jan 13, 2025
1 parent 54f4328 commit f8ab217
Showing 1 changed file with 110 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ describe("VideoConferenceComposable", () => {
const scopeId = "123124";

const FAKE_RESPONSE = {
state: VideoConferenceStateResponse.Running,
options: {
everyAttendeeJoinsMuted: true,
everybodyJoinsAsModerator: false,
moderatorMustApproveJoinRequests: true,
status: 200,
data: {
state: VideoConferenceStateResponse.Running,
options: {
everyAttendeeJoinsMuted: true,
everybodyJoinsAsModerator: false,
moderatorMustApproveJoinRequests: true,
},
},
};
videoConferenceApi.videoConferenceControllerInfo.mockResolvedValueOnce(
FAKE_RESPONSE as unknown as AxiosPromise<VideoConferenceInfoResponse>
);

const { fetchVideoConferenceInfo, error, videoConferenceInfo } =
useVideoConference(scope, scopeId);
Expand Down Expand Up @@ -69,13 +69,18 @@ describe("VideoConferenceComposable", () => {
it("should update videoConferenceInfo state with the response data", async () => {
const { fetchVideoConferenceInfo, videoConferenceInfo, FAKE_RESPONSE } =
setup();
videoConferenceApi.videoConferenceControllerInfo.mockResolvedValueOnce(
FAKE_RESPONSE as unknown as AxiosPromise<VideoConferenceInfoResponse>
);

await fetchVideoConferenceInfo();

expect(videoConferenceInfo.value.state).toBe(
VideoConferenceState.RUNNING
);
expect(videoConferenceInfo.value.options).toEqual(FAKE_RESPONSE.options);
expect(videoConferenceInfo.value.options).toEqual(
FAKE_RESPONSE.data.options
);
});

it("should set state to unknown if the response state is not recognized", async () => {
Expand Down Expand Up @@ -103,7 +108,13 @@ describe("VideoConferenceComposable", () => {
});

it("should set error if the API call fails", async () => {
const { scope, scopeId, fetchVideoConferenceInfo, error } = setup();
const scope = VideoConferenceScope.Room;
const scopeId = "123124";

const { fetchVideoConferenceInfo, error } = useVideoConference(
scope,
scopeId
);

const mockError = new Error("API call failed");
videoConferenceApi.videoConferenceControllerInfo.mockRejectedValueOnce(
Expand Down Expand Up @@ -167,6 +178,7 @@ describe("VideoConferenceComposable", () => {
logoutUrl,
});
});

it("should update videoConferenceInfo", async () => {
const { startVideoConference, videoConferenceInfo, logoutUrl } = setup();
const options = {
Expand All @@ -182,6 +194,7 @@ describe("VideoConferenceComposable", () => {
);
expect(videoConferenceInfo.value.options).toEqual(options);
});

it("should set error to null", async () => {
const { startVideoConference, error, logoutUrl } = setup();

Expand All @@ -195,9 +208,15 @@ describe("VideoConferenceComposable", () => {

expect(error.value).toBeNull();
});
it("should set error if the API call fails", async () => {
const { startVideoConference, error, logoutUrl } = setup();

it("should set error if the API call fails", async () => {
const scope = VideoConferenceScope.Room;
const scopeId = "123124";
const { startVideoConference, error } = useVideoConference(
scope,
scopeId
);
const logoutUrl = "https://logout.url";
const options = {
everyAttendeeJoinsMuted: true,
everybodyJoinsAsModerator: false,
Expand Down Expand Up @@ -241,6 +260,7 @@ describe("VideoConferenceComposable", () => {
url,
};
};

it("should call videoConferenceControllerJoin api with params", async () => {
const { scope, scopeId, joinVideoConference } = setup();

Expand All @@ -250,28 +270,32 @@ describe("VideoConferenceComposable", () => {
videoConferenceApi.videoConferenceControllerJoin
).toHaveBeenCalledWith(scope, scopeId);
});

it("should return the URL", async () => {
const { joinVideoConference, url } = setup();

const returnUrl = await joinVideoConference();

expect(url).toBe(returnUrl);
});

it("should set error to null", async () => {
const { joinVideoConference, error } = setup();

await joinVideoConference();

expect(error.value).toBeNull();
});
it("should set error if the API call fails", async () => {
const { scope, scopeId } = setup();
const { joinVideoConference, error } = useVideoConference(scope, scopeId);

it("should set error if the API call fails", async () => {
const scope = VideoConferenceScope.Room;
const scopeId = "123124";
const mockError = new Error("API call failed");

videoConferenceApi.videoConferenceControllerJoin.mockRejectedValueOnce(
mockError
);
const { joinVideoConference, error } = useVideoConference(scope, scopeId);

const url = await joinVideoConference();

Expand All @@ -293,11 +317,82 @@ describe("VideoConferenceComposable", () => {
resetError,
};
};

it("should set error to null", () => {
const { error, resetError } = setup();

resetError();
expect(error.value).toBeNull();
});
});

describe("isRunning", () => {
const setup = () => {
const scope = VideoConferenceScope.Room;
const scopeId = "123124";

const { isRunning, videoConferenceInfo } = useVideoConference(
scope,
scopeId
);

return {
isRunning,
videoConferenceInfo,
};
};

it("should return true when video conference state is RUNNING", () => {
const { isRunning, videoConferenceInfo } = setup();
videoConferenceInfo.value.state = VideoConferenceState.RUNNING;

expect(isRunning.value).toBe(true);
});

it("should return false when video conference state is NOT_STARTED", () => {
const { isRunning, videoConferenceInfo } = setup();
videoConferenceInfo.value.state = VideoConferenceState.NOT_STARTED;

expect(isRunning.value).toBe(false);
});

it("should return false when video conference state is UNKNOWN", () => {
const { isRunning, videoConferenceInfo } = setup();
videoConferenceInfo.value.state = VideoConferenceState.UNKNOWN;

expect(isRunning.value).toBe(false);
});
});

describe("isWaitingRoomActive", () => {
const setup = () => {
const scope = VideoConferenceScope.Room;
const scopeId = "123124";

const { isWaitingRoomActive, videoConferenceInfo } = useVideoConference(
scope,
scopeId
);

return {
isWaitingRoomActive,
videoConferenceInfo,
};
};

it("should return true when moderatorMustApproveJoinRequests is true", () => {
const { isWaitingRoomActive, videoConferenceInfo } = setup();
videoConferenceInfo.value.options.moderatorMustApproveJoinRequests = true;

expect(isWaitingRoomActive.value).toBe(true);
});

it("should return false when moderatorMustApproveJoinRequests is false", () => {
const { isWaitingRoomActive, videoConferenceInfo } = setup();
videoConferenceInfo.value.options.moderatorMustApproveJoinRequests =
false;

expect(isWaitingRoomActive.value).toBe(false);
});
});
});

0 comments on commit f8ab217

Please sign in to comment.