joinRoom.test.ts
1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { expect } from "chai";
import { RoomManager } from "../room/RoomManager";
import { DummySocket } from "./util/DummySocket";
import { prepareJoinedRoom, prepareUsersEmptyRooms } from "./util/prepare";
import { SocketTester } from "./util/SocketTester";
describe("방 입장", () => {
it("로그인하지 않은 유저는 요청할 수 없습니다", () => {
const roomManager = new RoomManager();
const socket = new SocketTester(roomManager);
const room = roomManager.create("테스트", 2);
socket.testNotOk("joinRoom", { uuid: room.uuid });
});
it("방에 입장합니다", () => {
const {
sockets: [socket],
rooms: [room],
} = prepareUsersEmptyRooms(1, 1);
const response = socket.test("joinRoom", { uuid: room.uuid });
expect(response.ok).eq(true);
expect(response.result?.uuid).eq(room.uuid);
expect(response.result?.name).eq(room.name);
expect(response.result?.maxUsers).eq(room.maxUsers);
expect(response.result?.users?.length).eq(1);
expect(response.result?.users[0]?.username).eq("guest1");
});
it("방에 입장하면 유저 목록이 업데이트 됩니다", () => {
const {
sockets: [socket1, socket2],
} = prepareJoinedRoom(2);
const updated = socket1.socket.received("updateRoomUser");
expect(updated.state).eq("added");
expect(updated.user.username).eq("guest2");
});
it("방에 이미 입장한 상태에서 다른 방에 입장할 수 없습니다", () => {
const {
sockets: [socket],
rooms: [room1, room2],
} = prepareUsersEmptyRooms(1, 2);
socket.testOk("joinRoom", { uuid: room1.uuid });
socket.testNotOk("joinRoom", { uuid: room2.uuid });
});
it("가득 찬 방에는 입장할 수 없습니다", () => {
const {
sockets: [socket1, socket2],
rooms: [room],
} = prepareUsersEmptyRooms(2, 1, 1);
socket1.testOk("joinRoom", { uuid: room.uuid });
socket2.testNotOk("joinRoom", { uuid: room.uuid });
});
});