강동현

게임 테스트 작성

import { expect } from "chai";
import { prepareGame } from "./util/prepare";
describe("라운드 단어 선택", () => {
it("drawer가 단어를 선택하면 wordChosen과 timer를 받습니다", () => {
const { drawerSocket, guesserSockets } = prepareGame(2);
const word = drawerSocket.socket.received("wordSet").words[0];
drawerSocket.testOk("chooseWord", { word });
expect(drawerSocket.socket.received("wordChosen").length).eq(word.length);
drawerSocket.socket.received("timer");
expect(guesserSockets[0].socket.received("wordChosen").length).eq(
word.length
);
guesserSockets[0].socket.received("timer");
});
it("drawer가 아닌 다른 사람들은 단어를 선택할 수 없습니다", () => {
const { drawerSocket, guesserSockets } = prepareGame(2);
const word = drawerSocket.socket.received("wordSet").words[0];
guesserSockets[0].testNotOk("chooseWord", { word });
});
it("단어를 이미 고른 상태에서 다시 고를 수 없습니다", () => {
const { drawerSocket } = prepareGame(2);
const word = drawerSocket.socket.received("wordSet").words[0];
drawerSocket.testOk("chooseWord", { word });
drawerSocket.testNotOk("chooseWord", { word });
});
it("목록에 없는 단어를 고를 수 없습니다", () => {
const { drawerSocket } = prepareGame(2);
drawerSocket.testNotOk("chooseWord", { word: "Nope!" });
});
});
import { expect } from "chai";
import { prepareGame } from "./util/prepare";
describe("라운드 브러시 이동", () => {
it("drawer가 브러시를 이동하면 다른 사람들이 설정을 받습니다", () => {
const { drawerSocket, guesserSockets } = prepareGame(2);
const brushCoord = { x: 0, y: 0 };
drawerSocket.testOk("moveBrush", brushCoord);
expect(guesserSockets[0].socket.received("moveBrush")).deep.eq(brushCoord);
});
it("영역을 벗어난 좌표는 Clamp 처리됩니다", () => {
const { drawerSocket, guesserSockets } = prepareGame(2);
drawerSocket.testOk("moveBrush", { x: -1, y: 2 });
expect(guesserSockets[0].socket.received("moveBrush")).deep.eq({
x: 0,
y: 1,
});
});
it("drawer가 아닌 다른 사람들은 브러시를 이동할 수 없습니다", () => {
const { guesserSockets } = prepareGame(2);
const brushCoord = { x: 0, y: 0 };
guesserSockets[0].testNotOk("moveBrush", brushCoord);
});
});
......@@ -66,14 +66,14 @@ describe("라운드", () => {
const { drawerSocket, guesserSockets } = prepareGame(3, 5, 0.5);
const word = drawerSocket.socket.received("wordSet").words[0];
expect(drawerSocket.test("chooseWord", { word }));
drawerSocket.testOk("chooseWord", { word });
// 0.1초 뒤에는 라운드가 종료되지 않습니다.
setTimeout(() => {
drawerSocket.socket.notReceived("finishRound");
// 첫번째 guesser가 단어를 맞춥니다.
guesserSockets[0].test("chat", { message: word });
guesserSockets[0].testOk("chat", { message: word });
expect(guesserSockets[0].socket.received("answerAccepted").answer).eq(
word
);
......@@ -83,7 +83,7 @@ describe("라운드", () => {
drawerSocket.socket.notReceived("finishRound");
// 두번째 guesser가 단어를 맞춥니다.
guesserSockets[1].test("chat", { message: word });
guesserSockets[1].testOk("chat", { message: word });
expect(guesserSockets[1].socket.received("answerAccepted").answer).eq(
word
);
......@@ -94,6 +94,80 @@ describe("라운드", () => {
done();
}, 300);
});
it("drawer가 단어를 선택하지 않고 나가면 즉시 라운드가 다시 시작됩니다", () => {
const { drawerSocket, guesserSockets } = prepareGame(3);
guesserSockets[0].socket.received("startRound");
guesserSockets[0].socket.notReceived("startRound");
drawerSocket.disconnect();
expect(guesserSockets[0].socket.received("startRound").round).eq(1);
});
it("drawer가 단어를 선택하지 않고 모든 guesser가 나가면 인원이 부족하므로 게임이 종료됩니다", () => {
const { drawerSocket, guesserSockets } = prepareGame(3);
drawerSocket.socket.notReceived("finishRound");
guesserSockets[0].disconnect();
drawerSocket.socket.notReceived("finishRound");
guesserSockets[1].disconnect();
drawerSocket.socket.received("finishRound");
drawerSocket.socket.received("finishGame");
});
it("drawer가 단어를 선택하고 모든 guesser가 나가면 인원이 부족하므로 게임이 종료됩니다", () => {
const { drawerSocket, guesserSockets } = 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");
});
it("drawer가 단어를 선택하고 나가면 라운드가 종료됩니다", () => {
const { drawerSocket, guesserSockets } = 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");
});
it("라운드가 종료되고 다음 라운드를 기다리는 동안 drawer가 나가도 다음 라운드가 시작됩니다", (done) => {
const { drawerSocket, guesserSockets } = 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[0].socket.received("finishRound");
guesserSockets[0].socket.notReceived("startRound");
drawerSocket.disconnect();
setTimeout(() => {
expect(guesserSockets[0].socket.received("startRound").round).eq(2);
done();
}, 200);
});
it("라운드가 종료되고 다음 라운드를 기다리는 동안 인원이 부족해지면 게임이 즉시 종료됩니다", () => {
const { drawerSocket, guesserSockets } = 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");
});
it("라운드가 종료되면 다음 라운드가 시작됩니다", (done) => {
const { drawerSocket, guesserSockets } = prepareGame(2, 5, 0.2, 0.2);
......@@ -121,4 +195,19 @@ describe("라운드", () => {
done();
}, 500);
});
it("마지막 라운드가 종료되면 게임이 종료됩니다", (done) => {
const { drawerSocket } = 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");
done();
}, 400);
});
});
......
import { expect } from "chai";
import { prepareGame } from "./util/prepare";
describe("라운드 채팅", () => {
it("guesser가 정답을 채팅으로 보내면 정답 처리되고 다른 사람들에게 채팅이 보이지 않습니다", () => {
const { drawerSocket, guesserSockets } = 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");
});
it("guesser가 정답을 채팅으로 보내면 역할이 winner로 변경됩니다", () => {
const { drawerSocket, guesserSockets } = 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",
});
});
it("라운드가 끝나고 다음 라운드를 준비하는 시간에 답을 채팅으로 보내도 정답 처리되지 않습니다", (done) => {
const { drawerSocket, guesserSockets } = 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");
done();
}, 200);
});
it("다음 라운드의 단어가 선택되지 않았을 때 이전 라운드의 답을 채팅으로 보내도 정답 처리되지 않습니다", (done) => {
const { drawerSocket, guesserSockets, game } = 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!");
}
done();
}, 400);
});
});
import { expect } from "chai";
import { prepareGame } from "./util/prepare";
describe("라운드 브러시 설정", () => {
it("drawer가 브러시를 설정하면 다른 사람들이 설정을 받습니다", () => {
const { drawerSocket, guesserSockets } = prepareGame(2);
const brushSettings = {
size: 1,
color: "000000",
drawing: true,
};
drawerSocket.testOk("setBrush", brushSettings);
expect(guesserSockets[0].socket.received("setBrush")).deep.eq(
brushSettings
);
});
it("올바르지 않은 브러시 설정은 허용되지 않습니다", () => {
const { drawerSocket } = prepareGame(2);
drawerSocket.testNotOk("setBrush", {
size: 0,
color: "000000",
drawing: true,
});
drawerSocket.testNotOk("setBrush", {
size: 100,
color: "000000",
drawing: true,
});
drawerSocket.testNotOk("setBrush", {
size: 1,
color: "000",
drawing: true,
});
drawerSocket.testNotOk("setBrush", {
size: 1,
color: "asdf01",
drawing: true,
});
});
it("drawer가 아닌 다른 사람들은 브러시를 설정할 수 없습니다", () => {
const { guesserSockets } = prepareGame(2);
const brushSettings = {
size: 1,
color: "000000",
drawing: true,
};
guesserSockets[0].testNotOk("setBrush", brushSettings);
});
});
......@@ -53,4 +53,8 @@ export class SocketTester {
this.testOk("login", { username });
expect(this.connection.user !== undefined).eq(true);
}
public disconnect(): void {
// TODO
}
}
......