ready.test.ts
3.81 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { expect } from "chai";
import { RoomManager } from "../room/RoomManager";
import { SocketTester } from "./util/SocketTester";
describe("준비", () => {
const roomManager = new RoomManager();
it("방에 입장하면 준비되지 않은 상태입니다", () => {
const socket = new SocketTester(roomManager);
socket.login("guest1");
const room = roomManager.create("테스트", 2);
const response = socket.test("joinRoom", { uuid: room.uuid });
expect(response.ok).eq(true);
expect(response.result?.users[0]?.username).eq("guest1");
expect(response.result?.users[0]?.ready).eq(false);
});
it("준비 상태를 설정합니다", () => {
const socket = new SocketTester(roomManager);
socket.login("guest1");
const room = roomManager.create("테스트", 2);
expect(socket.test("joinRoom", { uuid: room.uuid }).ok).eq(true);
expect(socket.connection.user !== undefined).eq(true);
if (socket.connection.user) {
expect(room.isReady(socket.connection.user)).eq(false);
expect(socket.test("ready", { ready: true }).ok).eq(true);
expect(room.isReady(socket.connection.user)).eq(true);
expect(socket.test("ready", { ready: false }).ok).eq(true);
expect(room.isReady(socket.connection.user)).eq(false);
}
});
it("방장은 준비할 수 없습니다", () => {
const socket = new SocketTester(roomManager);
socket.login("guest1");
expect(socket.connection.user !== undefined).eq(true);
if (socket.connection.user) {
const room = roomManager.create("테스트", 2, socket.connection.user);
expect(socket.test("ready", { ready: true }).ok).eq(false);
expect(room.isReady(socket.connection.user)).eq(false);
}
});
it("방장이 되면 준비 상태가 해제됩니다", () => {
const socket1 = new SocketTester(roomManager);
const socket2 = new SocketTester(roomManager);
socket1.login("guest1");
socket2.login("guest2");
expect(socket1.connection.user !== undefined).eq(true);
expect(socket2.connection.user !== undefined).eq(true);
if (socket1.connection.user && socket2.connection.user) {
const room = roomManager.create("테스트", 2, socket1.connection.user);
expect(socket2.test("joinRoom", { uuid: room.uuid }).ok).eq(true);
expect(socket2.test("ready", { ready: true }).ok).eq(true);
expect(room.isReady(socket2.connection.user));
room.setAdmin(socket2.connection.user);
expect(room.isReady(socket2.connection.user)).eq(false);
}
});
it("모두가 준비해야 게임을 시작할 수 있습니다", () => {
const socket1 = new SocketTester(roomManager);
const socket2 = new SocketTester(roomManager);
const socket3 = new SocketTester(roomManager);
socket1.login("guest1");
socket2.login("guest2");
socket3.login("guest3");
expect(socket1.connection.user !== undefined).eq(true);
expect(socket2.connection.user !== undefined).eq(true);
expect(socket3.connection.user !== undefined).eq(true);
if (
socket1.connection.user &&
socket2.connection.user &&
socket3.connection.user
) {
const room = roomManager.create("테스트", 3, socket1.connection.user);
expect(socket2.test("joinRoom", { uuid: room.uuid }).ok).eq(true);
expect(socket3.test("joinRoom", { uuid: room.uuid }).ok).eq(true);
// 2, 3 모두 준비 안함
expect(room.canStart()).eq(false);
// 2만 준비
expect(socket2.test("ready", { ready: true }).ok).eq(true);
// 3만 준비
expect(socket2.test("ready", { ready: false }).ok).eq(true);
expect(socket3.test("ready", { ready: true }).ok).eq(true);
expect(room.canStart()).eq(false);
// 2, 3 모두 준비
expect(socket2.test("ready", { ready: true }).ok).eq(true);
expect(room.canStart()).eq(true);
}
});
});