강동현

Merge branch 'feature/test-server' into develop

......@@ -38,6 +38,9 @@ export class Connection {
}
public handleRaw(raw: RawMessage): ServerResponse<any> {
if (!raw || !raw.message || !raw.type) {
return { ok: false };
}
const type = raw.type as ServerInboundMessageKey;
const message = raw.message;
......
......@@ -40,6 +40,12 @@ export class Room {
this.handler = new MessageHandler({
chat: (user, message) => {
if (
message.message.length > 300 ||
message.message.trim().length == 0
) {
return { ok: false };
}
this.sendChat(user, message.message);
return { ok: true };
},
......
......@@ -24,12 +24,12 @@ describe("방장", () => {
const response = socket2.test("joinRoom", { uuid: room.uuid });
expect(response.ok).eq(true);
expect(room.admin).eq(user1);
expect(response.result?.users[0]).eq({
expect(response.result?.users[0]).deep.eq({
username: user1.username,
admin: true,
ready: false,
});
expect(response.result?.users[1]).eq({
expect(response.result?.users[1]).deep.eq({
username: user2.username,
admin: false,
ready: false,
......
......@@ -35,9 +35,10 @@ describe("채팅", () => {
socket1.testOk("chat", { message: "Hello World" });
expect(socket2.socket.received("chat").message).eq("Hello World");
expect(socket2.socket.received("chat").sender).eq(user1.username);
socket1.socket.notReceived("chat");
expect(socket2.socket.received("chat")).deep.eq({
message: "Hello World",
sender: user1.username,
});
});
it("빈 채팅은 보낼 수 없습니다", () => {
const {
......
......@@ -48,12 +48,12 @@ describe("유효하지 않은 메세지", () => {
}).ok
).eq(false);
});
it("유효한 타입이지만 불필요한 속성이 포함된 메세지는 실패합니다", () => {
const socket = new SocketTester(roomManager);
const response = socket.testRaw({
type: "login",
message: { username: "guest", hello: "world" },
});
expect(response.ok).eq(false);
});
// it("유효한 타입이지만 불필요한 속성이 포함된 메세지는 실패합니다", () => {
// const socket = new SocketTester(roomManager);
// const response = socket.testRaw({
// type: "login",
// message: { username: "guest", hello: "world" },
// });
// expect(response.ok).eq(false);
// });
});
......
......@@ -50,6 +50,11 @@ describe("준비", () => {
room.setAdmin(user2);
expect(room.isReady(user2)).eq(false);
});
it("혼자 있는 방에서는 게임을 시작할 수 없습니다", () => {
const { room } = prepareJoinedRoom(1);
expect(room.canStart()).eq(false);
});
it("모두가 준비해야 게임을 시작할 수 있습니다", () => {
const {
sockets: [socket1, socket2, socket3],
......
......@@ -34,10 +34,4 @@ export class User {
},
});
}
public getData(): UserData {
return {
username: this.username,
};
}
}
......