강동현

게임 테스트 작성

1 +import { expect } from "chai";
2 +import { prepareGame } from "./util/prepare";
3 +
4 +describe("라운드 단어 선택", () => {
5 + it("drawer가 단어를 선택하면 wordChosen과 timer를 받습니다", () => {
6 + const { drawerSocket, guesserSockets } = prepareGame(2);
7 +
8 + const word = drawerSocket.socket.received("wordSet").words[0];
9 + drawerSocket.testOk("chooseWord", { word });
10 +
11 + expect(drawerSocket.socket.received("wordChosen").length).eq(word.length);
12 + drawerSocket.socket.received("timer");
13 + expect(guesserSockets[0].socket.received("wordChosen").length).eq(
14 + word.length
15 + );
16 + guesserSockets[0].socket.received("timer");
17 + });
18 + it("drawer가 아닌 다른 사람들은 단어를 선택할 수 없습니다", () => {
19 + const { drawerSocket, guesserSockets } = prepareGame(2);
20 +
21 + const word = drawerSocket.socket.received("wordSet").words[0];
22 +
23 + guesserSockets[0].testNotOk("chooseWord", { word });
24 + });
25 + it("단어를 이미 고른 상태에서 다시 고를 수 없습니다", () => {
26 + const { drawerSocket } = prepareGame(2);
27 +
28 + const word = drawerSocket.socket.received("wordSet").words[0];
29 + drawerSocket.testOk("chooseWord", { word });
30 + drawerSocket.testNotOk("chooseWord", { word });
31 + });
32 + it("목록에 없는 단어를 고를 수 없습니다", () => {
33 + const { drawerSocket } = prepareGame(2);
34 +
35 + drawerSocket.testNotOk("chooseWord", { word: "Nope!" });
36 + });
37 +});
1 +import { expect } from "chai";
2 +import { prepareGame } from "./util/prepare";
3 +
4 +describe("라운드 브러시 이동", () => {
5 + it("drawer가 브러시를 이동하면 다른 사람들이 설정을 받습니다", () => {
6 + const { drawerSocket, guesserSockets } = prepareGame(2);
7 +
8 + const brushCoord = { x: 0, y: 0 };
9 + drawerSocket.testOk("moveBrush", brushCoord);
10 + expect(guesserSockets[0].socket.received("moveBrush")).deep.eq(brushCoord);
11 + });
12 + it("영역을 벗어난 좌표는 Clamp 처리됩니다", () => {
13 + const { drawerSocket, guesserSockets } = prepareGame(2);
14 +
15 + drawerSocket.testOk("moveBrush", { x: -1, y: 2 });
16 + expect(guesserSockets[0].socket.received("moveBrush")).deep.eq({
17 + x: 0,
18 + y: 1,
19 + });
20 + });
21 + it("drawer가 아닌 다른 사람들은 브러시를 이동할 수 없습니다", () => {
22 + const { guesserSockets } = prepareGame(2);
23 +
24 + const brushCoord = { x: 0, y: 0 };
25 + guesserSockets[0].testNotOk("moveBrush", brushCoord);
26 + });
27 +});
...@@ -66,14 +66,14 @@ describe("라운드", () => { ...@@ -66,14 +66,14 @@ describe("라운드", () => {
66 const { drawerSocket, guesserSockets } = prepareGame(3, 5, 0.5); 66 const { drawerSocket, guesserSockets } = prepareGame(3, 5, 0.5);
67 67
68 const word = drawerSocket.socket.received("wordSet").words[0]; 68 const word = drawerSocket.socket.received("wordSet").words[0];
69 - expect(drawerSocket.test("chooseWord", { word })); 69 + drawerSocket.testOk("chooseWord", { word });
70 70
71 // 0.1초 뒤에는 라운드가 종료되지 않습니다. 71 // 0.1초 뒤에는 라운드가 종료되지 않습니다.
72 setTimeout(() => { 72 setTimeout(() => {
73 drawerSocket.socket.notReceived("finishRound"); 73 drawerSocket.socket.notReceived("finishRound");
74 74
75 // 첫번째 guesser가 단어를 맞춥니다. 75 // 첫번째 guesser가 단어를 맞춥니다.
76 - guesserSockets[0].test("chat", { message: word }); 76 + guesserSockets[0].testOk("chat", { message: word });
77 expect(guesserSockets[0].socket.received("answerAccepted").answer).eq( 77 expect(guesserSockets[0].socket.received("answerAccepted").answer).eq(
78 word 78 word
79 ); 79 );
...@@ -83,7 +83,7 @@ describe("라운드", () => { ...@@ -83,7 +83,7 @@ describe("라운드", () => {
83 drawerSocket.socket.notReceived("finishRound"); 83 drawerSocket.socket.notReceived("finishRound");
84 84
85 // 두번째 guesser가 단어를 맞춥니다. 85 // 두번째 guesser가 단어를 맞춥니다.
86 - guesserSockets[1].test("chat", { message: word }); 86 + guesserSockets[1].testOk("chat", { message: word });
87 expect(guesserSockets[1].socket.received("answerAccepted").answer).eq( 87 expect(guesserSockets[1].socket.received("answerAccepted").answer).eq(
88 word 88 word
89 ); 89 );
...@@ -94,6 +94,80 @@ describe("라운드", () => { ...@@ -94,6 +94,80 @@ describe("라운드", () => {
94 done(); 94 done();
95 }, 300); 95 }, 300);
96 }); 96 });
97 + it("drawer가 단어를 선택하지 않고 나가면 즉시 라운드가 다시 시작됩니다", () => {
98 + const { drawerSocket, guesserSockets } = prepareGame(3);
99 + guesserSockets[0].socket.received("startRound");
100 +
101 + guesserSockets[0].socket.notReceived("startRound");
102 + drawerSocket.disconnect();
103 + expect(guesserSockets[0].socket.received("startRound").round).eq(1);
104 + });
105 + it("drawer가 단어를 선택하지 않고 모든 guesser가 나가면 인원이 부족하므로 게임이 종료됩니다", () => {
106 + const { drawerSocket, guesserSockets } = prepareGame(3);
107 +
108 + drawerSocket.socket.notReceived("finishRound");
109 + guesserSockets[0].disconnect();
110 + drawerSocket.socket.notReceived("finishRound");
111 + guesserSockets[1].disconnect();
112 + drawerSocket.socket.received("finishRound");
113 + drawerSocket.socket.received("finishGame");
114 + });
115 + it("drawer가 단어를 선택하고 모든 guesser가 나가면 인원이 부족하므로 게임이 종료됩니다", () => {
116 + const { drawerSocket, guesserSockets } = prepareGame(3);
117 +
118 + const word = drawerSocket.socket.received("wordSet").words[0];
119 + drawerSocket.testOk("chooseWord", { word });
120 +
121 + drawerSocket.socket.notReceived("finishRound");
122 + guesserSockets[0].disconnect();
123 + drawerSocket.socket.notReceived("finishRound");
124 + guesserSockets[1].disconnect();
125 + drawerSocket.socket.received("finishRound");
126 + drawerSocket.socket.received("finishGame");
127 + });
128 + it("drawer가 단어를 선택하고 나가면 라운드가 종료됩니다", () => {
129 + const { drawerSocket, guesserSockets } = prepareGame(3);
130 +
131 + const word = drawerSocket.socket.received("wordSet").words[0];
132 + drawerSocket.testOk("chooseWord", { word });
133 +
134 + guesserSockets[0].socket.notReceived("finishRound");
135 + drawerSocket.disconnect();
136 + guesserSockets[0].socket.received("finishRound");
137 + guesserSockets[0].socket.notReceived("finishGame");
138 + });
139 + it("라운드가 종료되고 다음 라운드를 기다리는 동안 drawer가 나가도 다음 라운드가 시작됩니다", (done) => {
140 + const { drawerSocket, guesserSockets } = prepareGame(3, 5, 5, 0.1);
141 + guesserSockets[0].socket.received("startRound");
142 +
143 + const word = drawerSocket.socket.received("wordSet").words[0];
144 + drawerSocket.testOk("chooseWord", { word });
145 + guesserSockets[0].testOk("chat", { message: word });
146 +
147 + guesserSockets[0].socket.received("finishRound");
148 + guesserSockets[0].socket.notReceived("startRound");
149 +
150 + drawerSocket.disconnect();
151 +
152 + setTimeout(() => {
153 + expect(guesserSockets[0].socket.received("startRound").round).eq(2);
154 + done();
155 + }, 200);
156 + });
157 + it("라운드가 종료되고 다음 라운드를 기다리는 동안 인원이 부족해지면 게임이 즉시 종료됩니다", () => {
158 + const { drawerSocket, guesserSockets } = prepareGame(2, 5, 5, 0.1);
159 + guesserSockets[0].socket.received("startRound");
160 +
161 + const word = drawerSocket.socket.received("wordSet").words[0];
162 + drawerSocket.testOk("chooseWord", { word });
163 + guesserSockets[0].testOk("chat", { message: word });
164 +
165 + drawerSocket.socket.received("finishRound");
166 +
167 + guesserSockets[0].disconnect();
168 +
169 + drawerSocket.socket.received("finishGame");
170 + });
97 it("라운드가 종료되면 다음 라운드가 시작됩니다", (done) => { 171 it("라운드가 종료되면 다음 라운드가 시작됩니다", (done) => {
98 const { drawerSocket, guesserSockets } = prepareGame(2, 5, 0.2, 0.2); 172 const { drawerSocket, guesserSockets } = prepareGame(2, 5, 0.2, 0.2);
99 173
...@@ -121,4 +195,19 @@ describe("라운드", () => { ...@@ -121,4 +195,19 @@ describe("라운드", () => {
121 done(); 195 done();
122 }, 500); 196 }, 500);
123 }); 197 });
198 + it("마지막 라운드가 종료되면 게임이 종료됩니다", (done) => {
199 + const { drawerSocket } = prepareGame(2, 1, 0.1, 0.2);
200 +
201 + const word = drawerSocket.socket.received("wordSet").words[0];
202 + drawerSocket.testOk("chooseWord", { word });
203 +
204 + setTimeout(() => {
205 + drawerSocket.socket.received("finishRound");
206 + drawerSocket.socket.notReceived("finishGame");
207 + }, 200);
208 + setTimeout(() => {
209 + drawerSocket.socket.received("finishGame");
210 + done();
211 + }, 400);
212 + });
124 }); 213 });
......
1 +import { expect } from "chai";
2 +import { prepareGame } from "./util/prepare";
3 +
4 +describe("라운드 채팅", () => {
5 + it("guesser가 정답을 채팅으로 보내면 정답 처리되고 다른 사람들에게 채팅이 보이지 않습니다", () => {
6 + const { drawerSocket, guesserSockets } = prepareGame(3);
7 +
8 + const word = drawerSocket.socket.received("wordSet").words[0];
9 + drawerSocket.testOk("chooseWord", { word });
10 +
11 + guesserSockets[0].testOk("chat", { message: "Not Answer" });
12 + guesserSockets[0].socket.notReceived("answerAccepted");
13 + guesserSockets[1].socket.received("chat");
14 +
15 + guesserSockets[0].testOk("chat", { message: word });
16 + expect(guesserSockets[0].socket.received("answerAccepted").answer).eq(word);
17 + guesserSockets[1].socket.notReceived("chat");
18 + });
19 + it("guesser가 정답을 채팅으로 보내면 역할이 winner로 변경됩니다", () => {
20 + const { drawerSocket, guesserSockets } = prepareGame(2);
21 +
22 + const word = drawerSocket.socket.received("wordSet").words[0];
23 + drawerSocket.testOk("chooseWord", { word });
24 +
25 + guesserSockets[0].testOk("chat", { message: word });
26 +
27 + expect(guesserSockets[0].socket.received("role")).deep.eq({
28 + username: guesserSockets[0].connection.user?.username,
29 + role: "winner",
30 + });
31 + expect(drawerSocket.socket.received("role")).deep.eq({
32 + username: guesserSockets[0].connection.user?.username,
33 + role: "winner",
34 + });
35 + });
36 + it("라운드가 끝나고 다음 라운드를 준비하는 시간에 답을 채팅으로 보내도 정답 처리되지 않습니다", (done) => {
37 + const { drawerSocket, guesserSockets } = prepareGame(2, 5, 0.1, 0.3);
38 +
39 + const word = drawerSocket.socket.received("wordSet").words[0];
40 + drawerSocket.testOk("chooseWord", { word });
41 +
42 + guesserSockets[0].socket.notReceived("finishRound");
43 + setTimeout(() => {
44 + guesserSockets[0].socket.received("finishRound");
45 + guesserSockets[0].testOk("chat", { message: word });
46 + guesserSockets[0].socket.notReceived("answerAccepted");
47 + guesserSockets[0].socket.notReceived("role");
48 + done();
49 + }, 200);
50 + });
51 + it("다음 라운드의 단어가 선택되지 않았을 때 이전 라운드의 답을 채팅으로 보내도 정답 처리되지 않습니다", (done) => {
52 + const { drawerSocket, guesserSockets, game } = prepareGame(2, 5, 0.2, 0.1);
53 +
54 + const word = drawerSocket.socket.received("wordSet").words[0];
55 + drawerSocket.testOk("chooseWord", { word });
56 +
57 + expect(guesserSockets[0].socket.received("startRound").round).eq(1);
58 + setTimeout(() => {
59 + expect(guesserSockets[0].socket.received("startRound").round).eq(2);
60 +
61 + if (game.drawer === drawerSocket.connection.user) {
62 + guesserSockets[0].testOk("chat", { message: word });
63 + guesserSockets[0].socket.notReceived("answerAccepted");
64 + } else if (game.drawer === guesserSockets[0].connection.user) {
65 + drawerSocket.testOk("chat", { message: word });
66 + drawerSocket.socket.notReceived("answerAccepted");
67 + } else {
68 + throw new Error("There is no drawer!");
69 + }
70 + done();
71 + }, 400);
72 + });
73 +});
1 +import { expect } from "chai";
2 +import { prepareGame } from "./util/prepare";
3 +
4 +describe("라운드 브러시 설정", () => {
5 + it("drawer가 브러시를 설정하면 다른 사람들이 설정을 받습니다", () => {
6 + const { drawerSocket, guesserSockets } = prepareGame(2);
7 +
8 + const brushSettings = {
9 + size: 1,
10 + color: "000000",
11 + drawing: true,
12 + };
13 + drawerSocket.testOk("setBrush", brushSettings);
14 + expect(guesserSockets[0].socket.received("setBrush")).deep.eq(
15 + brushSettings
16 + );
17 + });
18 + it("올바르지 않은 브러시 설정은 허용되지 않습니다", () => {
19 + const { drawerSocket } = prepareGame(2);
20 +
21 + drawerSocket.testNotOk("setBrush", {
22 + size: 0,
23 + color: "000000",
24 + drawing: true,
25 + });
26 + drawerSocket.testNotOk("setBrush", {
27 + size: 100,
28 + color: "000000",
29 + drawing: true,
30 + });
31 + drawerSocket.testNotOk("setBrush", {
32 + size: 1,
33 + color: "000",
34 + drawing: true,
35 + });
36 + drawerSocket.testNotOk("setBrush", {
37 + size: 1,
38 + color: "asdf01",
39 + drawing: true,
40 + });
41 + });
42 + it("drawer가 아닌 다른 사람들은 브러시를 설정할 수 없습니다", () => {
43 + const { guesserSockets } = prepareGame(2);
44 +
45 + const brushSettings = {
46 + size: 1,
47 + color: "000000",
48 + drawing: true,
49 + };
50 + guesserSockets[0].testNotOk("setBrush", brushSettings);
51 + });
52 +});
...@@ -53,4 +53,8 @@ export class SocketTester { ...@@ -53,4 +53,8 @@ export class SocketTester {
53 this.testOk("login", { username }); 53 this.testOk("login", { username });
54 expect(this.connection.user !== undefined).eq(true); 54 expect(this.connection.user !== undefined).eq(true);
55 } 55 }
56 +
57 + public disconnect(): void {
58 + // TODO
59 + }
56 } 60 }
......