Skip to content

Commit ff87b1d

Browse files
committed
test: add test for joinRoom after cancelOrdinaryRoom
1 parent 57eef64 commit ff87b1d

File tree

4 files changed

+78
-2
lines changed

4 files changed

+78
-2
lines changed

src/v1/controller/room/info/__tests__/helpers/createUsersRequest.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@ export const createUsersRequest = (
2828
} as ControllerClassParams);
2929
};
3030

31-
export const createRoom = async (ownerUUID: string, roomUUID: string): Promise<void> => {
31+
export const createRoom = async (
32+
ownerUUID: string,
33+
roomUUID: string,
34+
roomStatus: RoomStatus = RoomStatus.Stopped,
35+
): Promise<void> => {
3236
await RoomDAO().insert({
3337
room_uuid: roomUUID,
3438
periodic_uuid: "",
35-
room_status: RoomStatus.Stopped,
39+
room_status: roomStatus,
3640
begin_time: new Date(),
3741
end_time: new Date(),
3842
title: "test",
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Logger } from "../../../../../../logger";
2+
import { CancelOrdinary } from "../../../cancel/Ordinary";
3+
4+
export const createCancel = (roomUUID: string, userUUID: string): CancelOrdinary => {
5+
const logger = new Logger<any>("test", {}, []);
6+
return new CancelOrdinary({
7+
logger,
8+
req: {
9+
body: {
10+
roomUUID,
11+
},
12+
user: {
13+
userUUID,
14+
},
15+
},
16+
reply: {},
17+
} as any);
18+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { JoinRoom } from "../..";
2+
import { Logger } from "../../../../../../logger";
3+
4+
export const createJoinRoom = (roomUUID: string, userUUID: string): JoinRoom => {
5+
const logger = new Logger<any>("test", {}, []);
6+
return new JoinRoom({
7+
logger,
8+
req: {
9+
body: {
10+
uuid: roomUUID,
11+
},
12+
user: {
13+
userUUID,
14+
},
15+
},
16+
reply: {},
17+
} as any);
18+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import test from "ava";
2+
import { dataSource } from "../../../../../thirdPartyService/TypeORMService";
3+
import { v4 } from "uuid";
4+
import { createRoom, createRoomUser } from "../../info/__tests__/helpers/createUsersRequest";
5+
import { createCancel } from "./helpers/createCancelOrdinary";
6+
import { createJoinRoom } from "./helpers/createJoinRoom";
7+
import { RoomStatus } from "../../../../../model/room/Constants";
8+
9+
const namespace = "[api][api-v1][api-v1-room][api-v1-room-join]";
10+
11+
test.before(`${namespace} - initialize dataSource`, async () => {
12+
await dataSource.initialize();
13+
});
14+
15+
test.after(`${namespace} - destroy dataSource`, async () => {
16+
await dataSource.destroy();
17+
});
18+
19+
test(`${namespace} - join after user cancel`, async ava => {
20+
const [roomUUID] = [v4()];
21+
const [ownerUUID, anotherUserUUID] = await createRoomUser(roomUUID, 2);
22+
await createRoom(ownerUUID, roomUUID, RoomStatus.Started);
23+
24+
const joinRoom = createJoinRoom(roomUUID, anotherUserUUID);
25+
const result = await joinRoom.execute();
26+
const f: number = (result as any).data.rtcUID;
27+
28+
await createCancel(roomUUID, anotherUserUUID).execute();
29+
30+
const joinRoom1 = createJoinRoom(roomUUID, anotherUserUUID);
31+
const join1Result = await joinRoom1.execute();
32+
const f1: number = (join1Result as any).data.rtcUID;
33+
34+
ava.is(f > 0 && f1 > 0, true);
35+
ava.is(f == f1, true);
36+
});

0 commit comments

Comments
 (0)