roundChat.test.ts
3.23 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
import { expect } from "chai";
import { clear } from "./util/clear";
import { prepareGame } from "./util/prepare";
describe("라운드 채팅", () => {
it("guesser가 정답을 채팅으로 보내면 정답 처리되고 다른 사람들에게 채팅이 보이지 않습니다", () => {
const { drawerSocket, guesserSockets, room } = prepareGame(3);
const word = drawerSocket.socket.received("wordSet").words[0];
drawerSocket.testOk("chooseWord", { word });
guesserSockets[0].testOk("chat", { message: "Not Answer" });
guesserSockets[0].socket.notReceived("answerAccepted");
guesserSockets[1].socket.received("chat");
guesserSockets[0].testOk("chat", { message: word });
expect(guesserSockets[0].socket.received("answerAccepted").answer).eq(word);
guesserSockets[1].socket.notReceived("chat");
clear([room]);
});
it("guesser가 정답을 채팅으로 보내면 역할이 winner로 변경됩니다", () => {
const { drawerSocket, guesserSockets, room } = prepareGame(2);
const word = drawerSocket.socket.received("wordSet").words[0];
drawerSocket.testOk("chooseWord", { word });
guesserSockets[0].testOk("chat", { message: word });
expect(guesserSockets[0].socket.received("role")).deep.eq({
username: guesserSockets[0].connection.user?.username,
role: "winner",
});
expect(drawerSocket.socket.received("role")).deep.eq({
username: guesserSockets[0].connection.user?.username,
role: "winner",
});
clear([room]);
});
it("라운드가 끝나고 다음 라운드를 준비하는 시간에 답을 채팅으로 보내도 정답 처리되지 않습니다", (done) => {
const { drawerSocket, guesserSockets, room } = prepareGame(2, 5, 0.1, 0.3);
const word = drawerSocket.socket.received("wordSet").words[0];
drawerSocket.testOk("chooseWord", { word });
guesserSockets[0].socket.notReceived("finishRound");
setTimeout(() => {
guesserSockets[0].socket.received("finishRound");
guesserSockets[0].testOk("chat", { message: word });
guesserSockets[0].socket.notReceived("answerAccepted");
guesserSockets[0].socket.notReceived("role");
clear([room]);
done();
}, 200);
});
it("다음 라운드의 단어가 선택되지 않았을 때 이전 라운드의 답을 채팅으로 보내도 정답 처리되지 않습니다", (done) => {
const { drawerSocket, guesserSockets, game, room } = prepareGame(
2,
5,
0.2,
0.1
);
const word = drawerSocket.socket.received("wordSet").words[0];
drawerSocket.testOk("chooseWord", { word });
expect(guesserSockets[0].socket.received("startRound").round).eq(1);
setTimeout(() => {
expect(guesserSockets[0].socket.received("startRound").round).eq(2);
if (game.drawer === drawerSocket.connection.user) {
guesserSockets[0].testOk("chat", { message: word });
guesserSockets[0].socket.notReceived("answerAccepted");
} else if (game.drawer === guesserSockets[0].connection.user) {
drawerSocket.testOk("chat", { message: word });
drawerSocket.socket.notReceived("answerAccepted");
} else {
throw new Error("There is no drawer!");
}
clear([room]);
done();
}, 400);
});
});