강동현

닉네임 로그인 테스트 작성, 기존 테스트 코드 닉네임으로 변경

......@@ -24,16 +24,14 @@ describe("방장", () => {
const response = socket2.test("joinRoom", { uuid: room.uuid });
expect(response.ok).eq(true);
expect(room.admin).eq(user1);
expect(response.result?.users[0]).deep.eq({
username: user1.username,
admin: true,
ready: false,
});
expect(response.result?.users[1]).deep.eq({
username: user2.username,
admin: false,
ready: false,
});
expect(response.result?.users[0].nickname).eq(user1.nickname);
expect(response.result?.users[0].admin).eq(true);
expect(response.result?.users[0].ready).eq(false);
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);
});
it("방장이 나가면 방장이 인계됩니다", () => {
const {
......
......@@ -14,6 +14,7 @@ describe("방 입장", () => {
it("방에 입장합니다", () => {
const {
sockets: [socket],
users: [user],
rooms: [room],
} = prepareUsersEmptyRooms(1, 1);
......@@ -23,16 +24,17 @@ describe("방 입장", () => {
expect(response.result?.name).eq(room.name);
expect(response.result?.maxUsers).eq(room.maxUsers);
expect(response.result?.users?.length).eq(1);
expect(response.result?.users[0]?.username).eq("guest1");
expect(response.result?.users[0]?.nickname).eq(user.nickname);
});
it("방에 입장하면 유저 목록이 업데이트 됩니다", () => {
const {
sockets: [socket1, socket2],
users: [user1, user2],
} = prepareJoinedRoom(2);
const updated = socket1.socket.received("updateRoomUser");
expect(updated.state).eq("added");
expect(updated.user.username).eq("guest2");
expect(updated.user.nickname).eq(user2.nickname);
});
it("방에 이미 입장한 상태에서 다른 방에 입장할 수 없습니다", () => {
const {
......
......@@ -3,10 +3,22 @@ import { RoomManager } from "../room/RoomManager";
import { SocketTester } from "./util/SocketTester";
describe("로그인", () => {
it("로그인합니다", () => {
it("닉네임으로 로그인합니다", () => {
const roomManager = new RoomManager();
const socket = new SocketTester(roomManager);
socket.testOk("login", { username: "guest" });
expect(socket.connection.user?.username).eq("guest");
socket.testOk("login", { nickname: "guest" });
expect(socket.connection.user?.nickname).eq("guest");
});
it("빈 닉네임으로 로그인할 수 없습니다", () => {
const roomManager = new RoomManager();
const socket = new SocketTester(roomManager);
socket.testNotOk("login", { nickname: "" });
socket.testNotOk("login", { nickname: " " });
});
it("닉네임은 최대 12자입니다", () => {
const roomManager = new RoomManager();
const socket = new SocketTester(roomManager);
socket.testNotOk("login", { nickname: "a".repeat(13) });
socket.testNotOk("login", { nickname: "가".repeat(13) });
});
});
......
......@@ -7,12 +7,13 @@ describe("준비", () => {
it("방에 입장하면 준비되지 않은 상태입니다", () => {
const {
sockets: [socket],
users: [user],
rooms: [room],
} = prepareUsersEmptyRooms(1, 1);
const response = socket.test("joinRoom", { uuid: room.uuid });
expect(response.ok).eq(true);
expect(response.result?.users[0]?.username).eq("guest1");
expect(response.result?.users[0]?.nickname).eq(user.nickname);
expect(response.result?.users[0]?.ready).eq(false);
});
it("준비 상태를 설정합니다", () => {
......@@ -26,25 +27,19 @@ describe("준비", () => {
socket.testOk("ready", { ready: true });
expect(room.isReady(user)).eq(true);
expect(socket.socket.received("updateRoomUser")).deep.eq({
state: "updated",
user: {
username: user.username,
admin: false,
ready: true,
},
});
let response = socket.socket.received("updateRoomUser");
expect(response.state).eq("updated");
expect(response.user.nickname).eq(user.nickname);
expect(response.user.ready).eq(true);
socket.testOk("ready", { ready: false });
expect(room.isReady(user)).eq(false);
expect(socket.socket.received("updateRoomUser")).deep.eq({
state: "updated",
user: {
username: user.username,
admin: false,
ready: false,
},
});
response = socket.socket.received("updateRoomUser");
expect(response.state).eq("updated");
expect(response.user.nickname).eq(user.nickname);
expect(response.user.ready).eq(false);
});
it("방장은 준비할 수 없습니다", () => {
const {
......
......@@ -49,8 +49,8 @@ export class SocketTester {
return this.connection.handleRaw(obj);
}
public login(username: string): void {
this.testOk("login", { username });
public login(nickname: string): void {
this.testOk("login", { nickname });
expect(this.connection.user !== undefined).eq(true);
}
......