round.test.ts
8.67 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
import { expect } from "chai";
import { clear } from "./util/clear";
import { prepareGame } from "./util/prepare";
describe("라운드", () => {
it("첫 라운드가 시작되면 startRound와 wordSet을 받습니다", () => {
const {
sockets: [socket1, socket2],
drawerSocket,
room,
} = prepareGame(2);
expect(socket1.socket.received("startRound").round).eq(1);
expect(socket2.socket.received("startRound").round).eq(1);
// drawer는 wordSet을 받습니다.
expect(drawerSocket.socket.received("wordSet").words.length).eq(3);
clear([room]);
});
it("drawer가 단어를 선택하면 모두가 wordChosen과 timer를 받습니다", () => {
const { drawerSocket, guesserSockets, room } = prepareGame(2);
const word = drawerSocket.socket.received("wordSet").words[0];
drawerSocket.testOk("chooseWord", { word });
expect(drawerSocket.socket.received("wordChosen").length).eq(word.length);
expect(guesserSockets[0].socket.received("wordChosen").length).eq(
word.length
);
let timerSettings = drawerSocket.socket.received("timer");
expect(timerSettings.state).eq(timerSettings.state);
expect(timerSettings.time).greaterThan(59);
clear([room]);
});
it("drawer가 단어를 선택하지 않으면 라운드가 진행되지 않습니다", (done) => {
const { drawerSocket, guesserSockets, room } = prepareGame(2, 5, 0.1);
// 0.2초 뒤에도 라운드가 종료되지 않습니다.
setTimeout(() => {
drawerSocket.socket.notReceived("finishRound");
guesserSockets[0].socket.notReceived("finishRound");
clear([room]);
done();
}, 200);
});
it("아무도 단어를 맞추지 못하고 시간이 지나면 라운드가 종료됩니다", (done) => {
const { drawerSocket, guesserSockets, room } = prepareGame(2, 5, 0.2);
const word = drawerSocket.socket.received("wordSet").words[0];
drawerSocket.testOk("chooseWord", { word });
// 0.1초 뒤에는 라운드가 종료되지 않습니다.
setTimeout(() => {
drawerSocket.socket.notReceived("finishRound");
guesserSockets[0].socket.notReceived("finishRound");
}, 100);
// 0.3초 뒤에는 라운드가 종료됩니다.
setTimeout(() => {
expect(drawerSocket.socket.received("finishRound").answer).eq(word);
expect(guesserSockets[0].socket.received("finishRound").answer).eq(word);
clear([room]);
done();
}, 300);
});
it("모든 guesser가 단어를 맞추면 라운드가 종료됩니다", (done) => {
const { drawerSocket, guesserSockets, room } = prepareGame(3, 5, 0.5);
const word = drawerSocket.socket.received("wordSet").words[0];
drawerSocket.testOk("chooseWord", { word });
// 0.1초 뒤에는 라운드가 종료되지 않습니다.
setTimeout(() => {
drawerSocket.socket.notReceived("finishRound");
// 첫번째 guesser가 단어를 맞춥니다.
guesserSockets[0].testOk("chat", { message: word });
expect(guesserSockets[0].socket.received("answerAccepted").answer).eq(
word
);
}, 100);
// 0.2초 뒤에도 라운드가 종료되지 않습니다.
setTimeout(() => {
drawerSocket.socket.notReceived("finishRound");
// 두번째 guesser가 단어를 맞춥니다.
guesserSockets[1].testOk("chat", { message: word });
expect(guesserSockets[1].socket.received("answerAccepted").answer).eq(
word
);
}, 200);
// 0.3초 뒤에는 라운드가 종료됩니다.
setTimeout(() => {
drawerSocket.socket.received("finishRound");
clear([room]);
done();
}, 300);
});
it("drawer가 단어를 선택하지 않고 나가면 즉시 라운드가 다시 시작됩니다", () => {
const { drawerSocket, guesserSockets, room } = prepareGame(3);
guesserSockets[0].socket.received("startRound");
guesserSockets[0].socket.notReceived("startRound");
drawerSocket.disconnect();
expect(guesserSockets[0].socket.received("startRound").round).eq(1);
clear([room]);
});
it("drawer가 단어를 선택하지 않고 모든 guesser가 나가면 인원이 부족하므로 게임이 종료됩니다", () => {
const { drawerSocket, guesserSockets, room } = prepareGame(3);
drawerSocket.socket.notReceived("finishRound");
guesserSockets[0].disconnect();
drawerSocket.socket.notReceived("finishRound");
guesserSockets[1].disconnect();
// 단어가 선택되지 않았으므로 finishRound가 수신되지 않습니다.
drawerSocket.socket.received("finishGame");
clear([room]);
});
it("drawer가 단어를 선택하고 모든 guesser가 나가면 인원이 부족하므로 게임이 종료됩니다", () => {
const { drawerSocket, guesserSockets, room } = prepareGame(3);
const word = drawerSocket.socket.received("wordSet").words[0];
drawerSocket.testOk("chooseWord", { word });
drawerSocket.socket.notReceived("finishRound");
guesserSockets[0].disconnect();
drawerSocket.socket.notReceived("finishRound");
guesserSockets[1].disconnect();
drawerSocket.socket.received("finishRound");
drawerSocket.socket.received("finishGame");
clear([room]);
});
it("drawer가 단어를 선택하고 나가면 라운드가 종료됩니다", () => {
const { drawerSocket, guesserSockets, room } = prepareGame(3);
const word = drawerSocket.socket.received("wordSet").words[0];
drawerSocket.testOk("chooseWord", { word });
guesserSockets[0].socket.notReceived("finishRound");
drawerSocket.disconnect();
guesserSockets[0].socket.received("finishRound");
guesserSockets[0].socket.notReceived("finishGame");
clear([room]);
});
it("라운드가 종료되고 다음 라운드를 기다리는 동안 drawer가 나가도 다음 라운드가 시작됩니다", (done) => {
const { drawerSocket, guesserSockets, room } = prepareGame(3, 5, 5, 0.1);
guesserSockets[0].socket.received("startRound");
const word = drawerSocket.socket.received("wordSet").words[0];
drawerSocket.testOk("chooseWord", { word });
guesserSockets[0].testOk("chat", { message: word });
guesserSockets[1].testOk("chat", { message: word });
guesserSockets[0].socket.received("finishRound");
guesserSockets[0].socket.notReceived("startRound");
drawerSocket.disconnect();
setTimeout(() => {
expect(guesserSockets[0].socket.received("startRound").round).eq(2);
clear([room]);
done();
}, 200);
});
it("라운드가 종료되고 다음 라운드를 기다리는 동안 인원이 부족해지면 게임이 즉시 종료됩니다", () => {
const { drawerSocket, guesserSockets, room } = prepareGame(2, 5, 5, 0.1);
guesserSockets[0].socket.received("startRound");
const word = drawerSocket.socket.received("wordSet").words[0];
drawerSocket.testOk("chooseWord", { word });
guesserSockets[0].testOk("chat", { message: word });
drawerSocket.socket.received("finishRound");
guesserSockets[0].disconnect();
drawerSocket.socket.received("finishGame");
clear([room]);
});
it("라운드가 종료되면 다음 라운드가 시작됩니다", (done) => {
const { drawerSocket, guesserSockets, room } = prepareGame(2, 5, 0.2, 0.2);
drawerSocket.socket.received("startRound");
guesserSockets[0].socket.received("startRound");
const word = drawerSocket.socket.received("wordSet").words[0];
drawerSocket.testOk("chooseWord", { word });
// 0.1초 뒤에는 라운드가 종료되지 않습니다.
setTimeout(() => {
drawerSocket.socket.notReceived("finishRound");
guesserSockets[0].socket.notReceived("finishRound");
}, 100);
// 0.3초 뒤에는 라운드가 종료됩니다.
setTimeout(() => {
expect(drawerSocket.socket.received("finishRound").answer).eq(word);
expect(guesserSockets[0].socket.received("finishRound").answer).eq(word);
drawerSocket.socket.notReceived("startRound");
}, 300);
// 0.5초 뒤에는 다음 라운드가 시작됩니다.
setTimeout(() => {
expect(drawerSocket.socket.received("startRound").round).eq(2);
expect(guesserSockets[0].socket.received("startRound").round).eq(2);
clear([room]);
done();
}, 500);
});
it("마지막 라운드가 종료되면 게임이 종료됩니다", (done) => {
const { drawerSocket, room } = prepareGame(2, 1, 0.1, 0.2);
const word = drawerSocket.socket.received("wordSet").words[0];
drawerSocket.testOk("chooseWord", { word });
setTimeout(() => {
drawerSocket.socket.received("finishRound");
drawerSocket.socket.notReceived("finishGame");
}, 200);
setTimeout(() => {
drawerSocket.socket.received("finishGame");
clear([room]);
done();
}, 400);
});
});