ready.test.ts
2.22 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
import { expect } from "chai";
import { RoomManager } from "../room/RoomManager";
import { prepareJoinedRoom, prepareUsersEmptyRooms } from "./util/prepare";
import { SocketTester } from "./util/SocketTester";
describe("준비", () => {
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?.users[0]?.username).eq("guest1");
expect(response.result?.users[0]?.ready).eq(false);
});
it("준비 상태를 설정합니다", () => {
const {
sockets: [socket],
users: [user],
room,
} = prepareJoinedRoom(1, 2, true);
expect(room.isReady(user)).eq(false);
socket.testOk("ready", { ready: true });
expect(room.isReady(user)).eq(true);
socket.testOk("ready", { ready: false });
expect(room.isReady(user)).eq(false);
});
it("방장은 준비할 수 없습니다", () => {
const {
sockets: [socket],
users: [user],
room,
} = prepareJoinedRoom(1, 2);
socket.testNotOk("ready", { ready: true });
expect(room.isReady(user)).eq(false);
});
it("방장이 되면 준비 상태가 해제됩니다", () => {
const {
sockets: [socket1, socket2],
users: [user1, user2],
room,
} = prepareJoinedRoom(2);
socket2.testOk("ready", { ready: true });
expect(room.isReady(user2)).eq(true);
room.setAdmin(user2);
expect(room.isReady(user2)).eq(false);
});
it("모두가 준비해야 게임을 시작할 수 있습니다", () => {
const {
sockets: [socket1, socket2, socket3],
room,
} = prepareJoinedRoom(3);
// 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);
});
});