leaveRoom.test.ts
2.47 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
56
57
58
59
60
61
62
63
64
65
66
import { expect } from "chai";
import { RoomManager } from "../room/RoomManager";
import { User } from "../user/User";
import { DummySocket } from "./util/DummySocket";
import { SocketTester } from "./util/SocketTester";
describe("방 퇴장", () => {
const roomManager = new RoomManager();
it("로그인하지 않은 유저는 요청할 수 없습니다", () => {
const socket = new SocketTester(roomManager);
const response = socket.test("leaveRoom", {});
expect(response.ok).eq(false);
});
it("방에 입장하지 않은 유저는 요청할 수 없습니다", () => {
const socket = new SocketTester(roomManager);
socket.login("guest");
const response = socket.test("leaveRoom", {});
expect(response.ok).eq(false);
});
it("방에서 퇴장합니다", () => {
const socket = new SocketTester(roomManager);
socket.login("guest");
const room = roomManager.create("테스트", 2);
expect(socket.test("joinRoom", { uuid: room.uuid }).ok).eq(true);
expect(socket.test("leaveRoom", {}).ok).eq(true);
});
it("방에서 퇴장한 뒤 다시 요청을 보낼 수 없습니다", () => {
const socket = new SocketTester(roomManager);
socket.login("guest");
const room = roomManager.create("테스트", 2);
expect(socket.test("joinRoom", { uuid: room.uuid }).ok).eq(true);
expect(socket.test("leaveRoom", {}).ok).eq(true);
expect(socket.test("leaveRoom", {}).ok).eq(false);
});
it("방에서 퇴장하면 유저 목록이 업데이트 됩니다", () => {
const socket1 = new SocketTester(roomManager);
const socket2 = new SocketTester(roomManager);
socket1.login("guest1");
socket2.login("guest2");
const room = roomManager.create("테스트", 2);
expect(socket1.test("joinRoom", { uuid: room.uuid }).ok).eq(true);
expect(socket2.test("joinRoom", { uuid: room.uuid }).ok).eq(true);
expect(socket2.test("leaveRoom", {}).ok).eq(true);
const updated = socket1.socket.received("updateRoomUser");
expect(updated.state).eq("removed");
expect(updated.user.username).eq("guest2");
});
it("방에서 퇴장한 뒤 아무도 없으면 방이 닫힙니다", () => {
const socket = new SocketTester(roomManager);
socket.login("guest1");
const room = roomManager.create("테스트", 1);
expect(socket.test("joinRoom", { uuid: room.uuid }).ok).eq(true);
expect(room.closed).eq(false);
expect(socket.test("leaveRoom", {}).ok).eq(true);
expect(room.closed).eq(true);
});
});