You need to sign in or sign up before continuing.
강동현

테스트가 끝나고 불필요한 딜레이가 발생하는 문제 해결

......@@ -186,9 +186,16 @@ export class Game {
}, this.roundTerm * 1000);
}
private finishGame(): void {
public finishGame(): void {
this.room.broadcast("finishGame", {});
if (this.timeoutTimerId) {
clearTimeout(this.timeoutTimerId);
}
if (this.nextRoundTimerId) {
clearTimeout(this.nextRoundTimerId);
}
this.room.finishGame();
}
......
......@@ -18,7 +18,7 @@
},
"scripts": {
"start": "nodemon index.ts",
"test": "nyc mocha -r ts-node/register --timeout 8000 ./**/*.test.ts",
"test": "nyc mocha -r ts-node/register --timeout 800 ./**/*.test.ts",
"build": "tsc -b -v"
},
"devDependencies": {
......
......@@ -37,4 +37,10 @@ export class RoomManager {
});
return roomData;
}
public clear() {
this.rooms.forEach((room) => {
room.close();
});
}
}
......
import { expect } from "chai";
import { RoomManager } from "../room/RoomManager";
import { clear } from "./util/clear";
import { prepareJoinedRoom, prepareUsers } from "./util/prepare";
import { SocketTester } from "./util/SocketTester";
......@@ -11,6 +12,8 @@ describe("방장", () => {
} = prepareJoinedRoom(1);
expect(room.admin).eq(user);
clear([room]);
});
it("나중에 들어온 유저는 방장 정보를 받지만 방장이 되지 않습니다", () => {
const {
......@@ -32,6 +35,8 @@ describe("방장", () => {
expect(response.result?.users[1].nickname).eq(user2.nickname);
expect(response.result?.users[1].admin).eq(false);
expect(response.result?.users[1].ready).eq(false);
clear([room]);
});
it("방장이 나가면 방장이 인계됩니다", () => {
const {
......@@ -43,6 +48,8 @@ describe("방장", () => {
expect(room.admin).eq(user1);
socket1.testOk("leaveRoom", {});
expect(room.admin).eq(user2);
clear([room]);
});
it("방장을 인계하면 정보가 업데이트됩니다", () => {
const {
......@@ -82,5 +89,7 @@ describe("방장", () => {
expect(message.state).eq("updated");
expect(message.user.username).eq(user2.username);
expect(message.user.admin).eq(true);
clear([room]);
});
});
......
import { expect } from "chai";
import { RoomManager } from "../room/RoomManager";
import { clear } from "./util/clear";
import { DummySocket } from "./util/DummySocket";
import {
prepareJoinedRoom,
......@@ -24,13 +25,16 @@ describe("채팅", () => {
it("채팅을 보냅니다", () => {
const {
sockets: [socket],
room,
} = prepareJoinedRoom(1);
socket.testOk("chat", { message: "Hello World" });
clear([room]);
});
it("모두가 채팅을 받습니다", () => {
const {
sockets: [socket1, socket2],
users: [user1, user2],
room,
} = prepareJoinedRoom(2);
socket1.testOk("chat", { message: "Hello World" });
......@@ -43,23 +47,31 @@ describe("채팅", () => {
message: "Hello World",
sender: user1.nickname,
});
clear([room]);
});
it("빈 채팅은 보낼 수 없습니다", () => {
const {
sockets: [socket],
room,
} = prepareJoinedRoom(1);
expect(socket.test("chat", { message: "" }).ok).eq(false);
expect(socket.test("chat", { message: " " }).ok).eq(false);
clear([room]);
});
it("글자수가 300자를 넘는 채팅은 보낼 수 없습니다", () => {
const {
sockets: [socket],
room,
} = prepareJoinedRoom(1);
expect(socket.test("chat", { message: "A".repeat(300) }).ok).eq(true);
expect(socket.test("chat", { message: "A".repeat(301) }).ok).eq(false);
expect(socket.test("chat", { message: "가".repeat(300) }).ok).eq(true);
expect(socket.test("chat", { message: "가".repeat(301) }).ok).eq(false);
clear([room]);
});
});
......
import { expect } from "chai";
import { clear } from "./util/clear";
import { prepareGame } from "./util/prepare";
describe("라운드 단어 선택", () => {
it("drawer가 단어를 선택하면 wordChosen과 timer를 받습니다", () => {
const { drawerSocket, guesserSockets } = prepareGame(2);
const { drawerSocket, guesserSockets, room } = prepareGame(2);
const word = drawerSocket.socket.received("wordSet").words[0];
drawerSocket.testOk("chooseWord", { word });
......@@ -14,24 +15,32 @@ describe("라운드 단어 선택", () => {
word.length
);
guesserSockets[0].socket.received("timer");
clear([room]);
});
it("drawer가 아닌 다른 사람들은 단어를 선택할 수 없습니다", () => {
const { drawerSocket, guesserSockets } = prepareGame(2);
const { drawerSocket, guesserSockets, room } = prepareGame(2);
const word = drawerSocket.socket.received("wordSet").words[0];
guesserSockets[0].testNotOk("chooseWord", { word });
clear([room]);
});
it("단어를 이미 고른 상태에서 다시 고를 수 없습니다", () => {
const { drawerSocket } = prepareGame(2);
const { drawerSocket, room } = prepareGame(2);
const word = drawerSocket.socket.received("wordSet").words[0];
drawerSocket.testOk("chooseWord", { word });
drawerSocket.testNotOk("chooseWord", { word });
clear([room]);
});
it("목록에 없는 단어를 고를 수 없습니다", () => {
const { drawerSocket } = prepareGame(2);
const { drawerSocket, room } = prepareGame(2);
drawerSocket.testNotOk("chooseWord", { word: "Nope!" });
clear([room]);
});
});
......
......@@ -17,6 +17,7 @@ describe("방 생성", () => {
const {
sockets: [socket],
users: [user],
roomManager,
} = prepareUsers(1);
const response = socket.test("createRoom", { name: "테스트" });
......@@ -24,15 +25,20 @@ describe("방 생성", () => {
expect(response.result?.name).eq("테스트");
expect(response.result?.users?.length).eq(1);
expect(response.result?.users[0]?.username).eq(user.username);
roomManager.clear();
});
it("방을 생성하면 방장이 됩니다", () => {
const {
sockets: [socket],
roomManager,
} = prepareUsers(1);
const response = socket.test("createRoom", { name: "테스트" });
expect(response.ok).eq(true);
expect(response.result?.users[0]?.admin).eq(true);
roomManager.clear();
});
it("방의 이름은 공백이 될 수 없습니다", () => {
const {
......
import { expect } from "chai";
import { RoomManager } from "../room/RoomManager";
import { clear } from "./util/clear";
import { DummySocket } from "./util/DummySocket";
import { prepareJoinedRoom, prepareUsersEmptyRooms } from "./util/prepare";
import { SocketTester } from "./util/SocketTester";
......@@ -10,6 +11,8 @@ describe("방 입장", () => {
const socket = new SocketTester(roomManager);
const room = roomManager.create("테스트", 2);
socket.testNotOk("joinRoom", { uuid: room.uuid });
clear([room]);
});
it("방에 입장합니다", () => {
const {
......@@ -25,16 +28,21 @@ describe("방 입장", () => {
expect(response.result?.maxUsers).eq(room.maxUsers);
expect(response.result?.users?.length).eq(1);
expect(response.result?.users[0]?.nickname).eq(user.nickname);
clear([room]);
});
it("방에 입장하면 유저 목록이 업데이트 됩니다", () => {
const {
sockets: [socket1, socket2],
users: [user1, user2],
room,
} = prepareJoinedRoom(2);
const updated = socket1.socket.received("updateRoomUser");
expect(updated.state).eq("added");
expect(updated.user.nickname).eq(user2.nickname);
clear([room]);
});
it("방에 이미 입장한 상태에서 다른 방에 입장할 수 없습니다", () => {
const {
......@@ -44,6 +52,8 @@ describe("방 입장", () => {
socket.testOk("joinRoom", { uuid: room1.uuid });
socket.testNotOk("joinRoom", { uuid: room2.uuid });
clear([room1, room2]);
});
it("가득 찬 방에는 입장할 수 없습니다", () => {
const {
......@@ -53,5 +63,7 @@ describe("방 입장", () => {
socket1.testOk("joinRoom", { uuid: room.uuid });
socket2.testNotOk("joinRoom", { uuid: room.uuid });
clear([room]);
});
});
......
import { expect } from "chai";
import { RoomManager } from "../room/RoomManager";
import { User } from "../user/User";
import { clear } from "./util/clear";
import { DummySocket } from "./util/DummySocket";
import { prepareJoinedRoom, prepareUsers } from "./util/prepare";
import { SocketTester } from "./util/SocketTester";
......@@ -27,25 +28,33 @@ describe("방 퇴장", () => {
expect(room.users.length).eq(1);
socket.testOk("leaveRoom", {});
expect(room.users.length).eq(0);
clear([room]);
});
it("방에서 퇴장한 뒤 다시 요청을 보낼 수 없습니다", () => {
const {
sockets: [socket],
room,
} = prepareJoinedRoom(1);
socket.testOk("leaveRoom", {});
socket.testNotOk("leaveRoom", {});
clear([room]);
});
it("방에서 퇴장하면 유저 목록이 업데이트 됩니다", () => {
const {
sockets: [socket1, socket2],
users: [user1, user2],
room,
} = prepareJoinedRoom(2);
socket1.testOk("leaveRoom", {});
const updated = socket2.socket.received("updateRoomUser");
expect(updated.state).eq("removed");
expect(updated.user.username).eq(user1.username);
clear([room]);
});
it("방에서 퇴장한 뒤 아무도 없으면 방이 닫힙니다", () => {
const {
......@@ -56,5 +65,7 @@ describe("방 퇴장", () => {
expect(room.closed).eq(false);
expect(socket.test("leaveRoom", {}).ok).eq(true);
expect(room.closed).eq(true);
clear([room]);
});
});
......
import { expect } from "chai";
import { clear } from "./util/clear";
import { prepareGame } from "./util/prepare";
describe("라운드 브러시 이동", () => {
it("drawer가 브러시를 이동하면 다른 사람들이 설정을 받습니다", () => {
const { drawerSocket, guesserSockets } = prepareGame(2);
const { drawerSocket, guesserSockets, room } = prepareGame(2);
const brushCoord = { x: 0, y: 0 };
drawerSocket.testOk("moveBrush", brushCoord);
expect(guesserSockets[0].socket.received("moveBrush")).deep.eq(brushCoord);
clear([room]);
});
it("영역을 벗어난 좌표는 Clamp 처리됩니다", () => {
const { drawerSocket, guesserSockets } = prepareGame(2);
const { drawerSocket, guesserSockets, room } = prepareGame(2);
drawerSocket.testOk("moveBrush", { x: -1, y: 1000 });
expect(guesserSockets[0].socket.received("moveBrush")).deep.eq({
x: 0,
y: 480,
});
clear([room]);
});
it("drawer가 아닌 다른 사람들은 브러시를 이동할 수 없습니다", () => {
const { guesserSockets } = prepareGame(2);
const { guesserSockets, room } = prepareGame(2);
const brushCoord = { x: 0, y: 0 };
guesserSockets[0].testNotOk("moveBrush", brushCoord);
clear([room]);
});
});
......
import { expect } from "chai";
import { RoomManager } from "../room/RoomManager";
import { clear } from "./util/clear";
import { prepareJoinedRoom, prepareUsersEmptyRooms } from "./util/prepare";
import { SocketTester } from "./util/SocketTester";
......@@ -15,6 +16,8 @@ describe("준비", () => {
expect(response.ok).eq(true);
expect(response.result?.users[0]?.nickname).eq(user.nickname);
expect(response.result?.users[0]?.ready).eq(false);
clear([room]);
});
it("준비 상태를 설정합니다", () => {
const {
......@@ -40,6 +43,8 @@ describe("준비", () => {
expect(response.state).eq("updated");
expect(response.user.nickname).eq(user.nickname);
expect(response.user.ready).eq(false);
clear([room]);
});
it("방장은 준비할 수 없습니다", () => {
const {
......@@ -50,6 +55,8 @@ describe("준비", () => {
socket.testNotOk("ready", { ready: true });
expect(room.isReady(user)).eq(false);
clear([room]);
});
it("방장이 되면 준비 상태가 해제됩니다", () => {
const {
......@@ -62,11 +69,15 @@ describe("준비", () => {
expect(room.isReady(user2)).eq(true);
room.setAdmin(user2);
expect(room.isReady(user2)).eq(false);
clear([room]);
});
it("혼자 있는 방에서는 게임을 시작할 수 없습니다", () => {
const { room } = prepareJoinedRoom(1);
expect(room.canStart().ok).eq(false);
clear([room]);
});
it("모두가 준비해야 게임을 시작할 수 있습니다", () => {
const {
......@@ -88,5 +99,7 @@ describe("준비", () => {
// 2, 3 모두 준비
expect(socket2.test("ready", { ready: true }).ok).eq(true);
expect(room.canStart().ok).eq(true);
clear([room]);
});
});
......
import { expect } from "chai";
import { RoomManager } from "../room/RoomManager";
import { clear } from "./util/clear";
import { DummySocket } from "./util/DummySocket";
import { prepareUsersEmptyRooms } from "./util/prepare";
import { SocketTester } from "./util/SocketTester";
......@@ -21,5 +22,7 @@ describe("방 목록 요청", () => {
expect(response.result?.length).eq(2);
expect(response.result[0].name).eq(room1.name);
expect(response.result[1].name).eq(room2.name);
clear([room1, room2]);
});
});
......
import { expect } from "chai";
import { clear } from "./util/clear";
import { prepareGame } from "./util/prepare";
describe("라운드", () => {
......@@ -6,6 +7,7 @@ describe("라운드", () => {
const {
sockets: [socket1, socket2],
drawerSocket,
room,
} = prepareGame(2);
expect(socket1.socket.received("startRound").round).eq(1);
......@@ -13,9 +15,11 @@ describe("라운드", () => {
// drawer는 wordSet을 받습니다.
expect(drawerSocket.socket.received("wordSet").words.length).eq(3);
clear([room]);
});
it("drawer가 단어를 선택하면 모두가 wordChosen과 timer를 받습니다", () => {
const { drawerSocket, guesserSockets } = prepareGame(2);
const { drawerSocket, guesserSockets, room } = prepareGame(2);
const word = drawerSocket.socket.received("wordSet").words[0];
drawerSocket.testOk("chooseWord", { word });
......@@ -28,19 +32,23 @@ describe("라운드", () => {
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 } = prepareGame(2, 5, 0.1);
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 } = prepareGame(2, 5, 0.2);
const { drawerSocket, guesserSockets, room } = prepareGame(2, 5, 0.2);
const word = drawerSocket.socket.received("wordSet").words[0];
drawerSocket.testOk("chooseWord", { word });
......@@ -54,11 +62,13 @@ describe("라운드", () => {
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 } = prepareGame(3, 5, 0.5);
const { drawerSocket, guesserSockets, room } = prepareGame(3, 5, 0.5);
const word = drawerSocket.socket.received("wordSet").words[0];
drawerSocket.testOk("chooseWord", { word });
......@@ -86,19 +96,23 @@ describe("라운드", () => {
// 0.3초 뒤에는 라운드가 종료됩니다.
setTimeout(() => {
drawerSocket.socket.received("finishRound");
clear([room]);
done();
}, 300);
});
it("drawer가 단어를 선택하지 않고 나가면 즉시 라운드가 다시 시작됩니다", () => {
const { drawerSocket, guesserSockets } = prepareGame(3);
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 } = prepareGame(3);
const { drawerSocket, guesserSockets, room } = prepareGame(3);
drawerSocket.socket.notReceived("finishRound");
guesserSockets[0].disconnect();
......@@ -106,9 +120,11 @@ describe("라운드", () => {
guesserSockets[1].disconnect();
// 단어가 선택되지 않았으므로 finishRound가 수신되지 않습니다.
drawerSocket.socket.received("finishGame");
clear([room]);
});
it("drawer가 단어를 선택하고 모든 guesser가 나가면 인원이 부족하므로 게임이 종료됩니다", () => {
const { drawerSocket, guesserSockets } = prepareGame(3);
const { drawerSocket, guesserSockets, room } = prepareGame(3);
const word = drawerSocket.socket.received("wordSet").words[0];
drawerSocket.testOk("chooseWord", { word });
......@@ -119,9 +135,11 @@ describe("라운드", () => {
guesserSockets[1].disconnect();
drawerSocket.socket.received("finishRound");
drawerSocket.socket.received("finishGame");
clear([room]);
});
it("drawer가 단어를 선택하고 나가면 라운드가 종료됩니다", () => {
const { drawerSocket, guesserSockets } = prepareGame(3);
const { drawerSocket, guesserSockets, room } = prepareGame(3);
const word = drawerSocket.socket.received("wordSet").words[0];
drawerSocket.testOk("chooseWord", { word });
......@@ -130,9 +148,11 @@ describe("라운드", () => {
drawerSocket.disconnect();
guesserSockets[0].socket.received("finishRound");
guesserSockets[0].socket.notReceived("finishGame");
clear([room]);
});
it("라운드가 종료되고 다음 라운드를 기다리는 동안 drawer가 나가도 다음 라운드가 시작됩니다", (done) => {
const { drawerSocket, guesserSockets } = prepareGame(3, 5, 5, 0.1);
const { drawerSocket, guesserSockets, room } = prepareGame(3, 5, 5, 0.1);
guesserSockets[0].socket.received("startRound");
const word = drawerSocket.socket.received("wordSet").words[0];
......@@ -147,11 +167,13 @@ describe("라운드", () => {
setTimeout(() => {
expect(guesserSockets[0].socket.received("startRound").round).eq(2);
clear([room]);
done();
}, 200);
});
it("라운드가 종료되고 다음 라운드를 기다리는 동안 인원이 부족해지면 게임이 즉시 종료됩니다", () => {
const { drawerSocket, guesserSockets } = prepareGame(2, 5, 5, 0.1);
const { drawerSocket, guesserSockets, room } = prepareGame(2, 5, 5, 0.1);
guesserSockets[0].socket.received("startRound");
const word = drawerSocket.socket.received("wordSet").words[0];
......@@ -163,9 +185,11 @@ describe("라운드", () => {
guesserSockets[0].disconnect();
drawerSocket.socket.received("finishGame");
clear([room]);
});
it("라운드가 종료되면 다음 라운드가 시작됩니다", (done) => {
const { drawerSocket, guesserSockets } = prepareGame(2, 5, 0.2, 0.2);
const { drawerSocket, guesserSockets, room } = prepareGame(2, 5, 0.2, 0.2);
drawerSocket.socket.received("startRound");
guesserSockets[0].socket.received("startRound");
......@@ -188,11 +212,13 @@ describe("라운드", () => {
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 } = prepareGame(2, 1, 0.1, 0.2);
const { drawerSocket, room } = prepareGame(2, 1, 0.1, 0.2);
const word = drawerSocket.socket.received("wordSet").words[0];
drawerSocket.testOk("chooseWord", { word });
......@@ -203,6 +229,8 @@ describe("라운드", () => {
}, 200);
setTimeout(() => {
drawerSocket.socket.received("finishGame");
clear([room]);
done();
}, 400);
});
......
import { expect } from "chai";
import { clear } from "./util/clear";
import { prepareGame } from "./util/prepare";
describe("라운드 채팅", () => {
it("guesser가 정답을 채팅으로 보내면 정답 처리되고 다른 사람들에게 채팅이 보이지 않습니다", () => {
const { drawerSocket, guesserSockets } = prepareGame(3);
const { drawerSocket, guesserSockets, room } = prepareGame(3);
const word = drawerSocket.socket.received("wordSet").words[0];
drawerSocket.testOk("chooseWord", { word });
......@@ -15,9 +16,11 @@ describe("라운드 채팅", () => {
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 } = prepareGame(2);
const { drawerSocket, guesserSockets, room } = prepareGame(2);
const word = drawerSocket.socket.received("wordSet").words[0];
drawerSocket.testOk("chooseWord", { word });
......@@ -32,9 +35,11 @@ describe("라운드 채팅", () => {
username: guesserSockets[0].connection.user?.username,
role: "winner",
});
clear([room]);
});
it("라운드가 끝나고 다음 라운드를 준비하는 시간에 답을 채팅으로 보내도 정답 처리되지 않습니다", (done) => {
const { drawerSocket, guesserSockets } = prepareGame(2, 5, 0.1, 0.3);
const { drawerSocket, guesserSockets, room } = prepareGame(2, 5, 0.1, 0.3);
const word = drawerSocket.socket.received("wordSet").words[0];
drawerSocket.testOk("chooseWord", { word });
......@@ -45,11 +50,18 @@ describe("라운드 채팅", () => {
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 } = prepareGame(2, 5, 0.2, 0.1);
const { drawerSocket, guesserSockets, game, room } = prepareGame(
2,
5,
0.2,
0.1
);
const word = drawerSocket.socket.received("wordSet").words[0];
drawerSocket.testOk("chooseWord", { word });
......@@ -67,6 +79,8 @@ describe("라운드 채팅", () => {
} else {
throw new Error("There is no drawer!");
}
clear([room]);
done();
}, 400);
});
......
import { expect } from "chai";
import { clear } from "./util/clear";
import { prepareGame } from "./util/prepare";
describe("라운드 브러시 설정", () => {
it("drawer가 브러시를 설정하면 다른 사람들이 설정을 받습니다", () => {
const { drawerSocket, guesserSockets } = prepareGame(2);
const { drawerSocket, guesserSockets, room } = prepareGame(2);
const brushSettings = {
size: 1,
......@@ -14,9 +15,11 @@ describe("라운드 브러시 설정", () => {
expect(guesserSockets[0].socket.received("setBrush")).deep.eq(
brushSettings
);
clear([room]);
});
it("올바르지 않은 브러시 색상은 허용되지 않습니다", () => {
const { drawerSocket } = prepareGame(2);
const { drawerSocket, room } = prepareGame(2);
drawerSocket.testNotOk("setBrush", {
size: 1,
color: "000",
......@@ -27,9 +30,11 @@ describe("라운드 브러시 설정", () => {
color: "asdf01",
drawing: true,
});
clear([room]);
});
it("올바르지 않은 브러시 사이즈는 Clamp 됩니다", () => {
const { drawerSocket, guesserSockets } = prepareGame(2);
const { drawerSocket, guesserSockets, room } = prepareGame(2);
drawerSocket.testOk("setBrush", {
size: 0,
color: "000000",
......@@ -42,9 +47,11 @@ describe("라운드 브러시 설정", () => {
drawing: true,
});
expect(guesserSockets[0].socket.received("setBrush").size).eq(64);
clear([room]);
});
it("drawer가 아닌 다른 사람들은 브러시를 설정할 수 없습니다", () => {
const { guesserSockets } = prepareGame(2);
const { guesserSockets, room } = prepareGame(2);
const brushSettings = {
size: 1,
......@@ -52,5 +59,7 @@ describe("라운드 브러시 설정", () => {
drawing: true,
};
guesserSockets[0].testNotOk("setBrush", brushSettings);
clear([room]);
});
});
......
import { expect } from "chai";
import { clear } from "./util/clear";
import { prepareJoinedRoom, prepareUsersEmptyRooms } from "./util/prepare";
describe("게임 시작", () => {
......@@ -14,17 +15,23 @@ describe("게임 시작", () => {
expect(socket2.testNotOk("startGame", {}));
expect(socket1.testOk("startGame", {}));
clear([room]);
});
it("인원이 충분해야 게임을 시작할 수 있습니다.", () => {
const {
sockets: [socket1],
room,
} = prepareJoinedRoom(1);
expect(socket1.testNotOk("startGame", {}));
clear([room]);
});
it("게임이 시작되면 startRound를 받습니다.", () => {
const {
sockets: [socket1, socket2],
room,
} = prepareJoinedRoom(2);
expect(socket2.testOk("ready", { ready: true }));
......@@ -32,5 +39,7 @@ describe("게임 시작", () => {
expect(socket1.socket.received("startRound"));
expect(socket2.socket.received("startRound"));
clear([room]);
});
});
......
import { Game } from "../../game/Game";
import { Room } from "../../room/Room";
export function clear(rooms: Room[]): void {
rooms.forEach((room) => {
room.game?.finishGame();
room.close();
});
}