강동현

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

...@@ -24,16 +24,14 @@ describe("방장", () => { ...@@ -24,16 +24,14 @@ describe("방장", () => {
24 const response = socket2.test("joinRoom", { uuid: room.uuid }); 24 const response = socket2.test("joinRoom", { uuid: room.uuid });
25 expect(response.ok).eq(true); 25 expect(response.ok).eq(true);
26 expect(room.admin).eq(user1); 26 expect(room.admin).eq(user1);
27 - expect(response.result?.users[0]).deep.eq({ 27 +
28 - username: user1.username, 28 + expect(response.result?.users[0].nickname).eq(user1.nickname);
29 - admin: true, 29 + expect(response.result?.users[0].admin).eq(true);
30 - ready: false, 30 + expect(response.result?.users[0].ready).eq(false);
31 - }); 31 +
32 - expect(response.result?.users[1]).deep.eq({ 32 + expect(response.result?.users[1].nickname).eq(user2.nickname);
33 - username: user2.username, 33 + expect(response.result?.users[1].admin).eq(false);
34 - admin: false, 34 + expect(response.result?.users[1].ready).eq(false);
35 - ready: false,
36 - });
37 }); 35 });
38 it("방장이 나가면 방장이 인계됩니다", () => { 36 it("방장이 나가면 방장이 인계됩니다", () => {
39 const { 37 const {
......
...@@ -14,6 +14,7 @@ describe("방 입장", () => { ...@@ -14,6 +14,7 @@ describe("방 입장", () => {
14 it("방에 입장합니다", () => { 14 it("방에 입장합니다", () => {
15 const { 15 const {
16 sockets: [socket], 16 sockets: [socket],
17 + users: [user],
17 rooms: [room], 18 rooms: [room],
18 } = prepareUsersEmptyRooms(1, 1); 19 } = prepareUsersEmptyRooms(1, 1);
19 20
...@@ -23,16 +24,17 @@ describe("방 입장", () => { ...@@ -23,16 +24,17 @@ describe("방 입장", () => {
23 expect(response.result?.name).eq(room.name); 24 expect(response.result?.name).eq(room.name);
24 expect(response.result?.maxUsers).eq(room.maxUsers); 25 expect(response.result?.maxUsers).eq(room.maxUsers);
25 expect(response.result?.users?.length).eq(1); 26 expect(response.result?.users?.length).eq(1);
26 - expect(response.result?.users[0]?.username).eq("guest1"); 27 + expect(response.result?.users[0]?.nickname).eq(user.nickname);
27 }); 28 });
28 it("방에 입장하면 유저 목록이 업데이트 됩니다", () => { 29 it("방에 입장하면 유저 목록이 업데이트 됩니다", () => {
29 const { 30 const {
30 sockets: [socket1, socket2], 31 sockets: [socket1, socket2],
32 + users: [user1, user2],
31 } = prepareJoinedRoom(2); 33 } = prepareJoinedRoom(2);
32 34
33 const updated = socket1.socket.received("updateRoomUser"); 35 const updated = socket1.socket.received("updateRoomUser");
34 expect(updated.state).eq("added"); 36 expect(updated.state).eq("added");
35 - expect(updated.user.username).eq("guest2"); 37 + expect(updated.user.nickname).eq(user2.nickname);
36 }); 38 });
37 it("방에 이미 입장한 상태에서 다른 방에 입장할 수 없습니다", () => { 39 it("방에 이미 입장한 상태에서 다른 방에 입장할 수 없습니다", () => {
38 const { 40 const {
......
...@@ -3,10 +3,22 @@ import { RoomManager } from "../room/RoomManager"; ...@@ -3,10 +3,22 @@ import { RoomManager } from "../room/RoomManager";
3 import { SocketTester } from "./util/SocketTester"; 3 import { SocketTester } from "./util/SocketTester";
4 4
5 describe("로그인", () => { 5 describe("로그인", () => {
6 - it("로그인합니다", () => { 6 + it("닉네임으로 로그인합니다", () => {
7 const roomManager = new RoomManager(); 7 const roomManager = new RoomManager();
8 const socket = new SocketTester(roomManager); 8 const socket = new SocketTester(roomManager);
9 - socket.testOk("login", { username: "guest" }); 9 + socket.testOk("login", { nickname: "guest" });
10 - expect(socket.connection.user?.username).eq("guest"); 10 + expect(socket.connection.user?.nickname).eq("guest");
11 + });
12 + it("빈 닉네임으로 로그인할 수 없습니다", () => {
13 + const roomManager = new RoomManager();
14 + const socket = new SocketTester(roomManager);
15 + socket.testNotOk("login", { nickname: "" });
16 + socket.testNotOk("login", { nickname: " " });
17 + });
18 + it("닉네임은 최대 12자입니다", () => {
19 + const roomManager = new RoomManager();
20 + const socket = new SocketTester(roomManager);
21 + socket.testNotOk("login", { nickname: "a".repeat(13) });
22 + socket.testNotOk("login", { nickname: "가".repeat(13) });
11 }); 23 });
12 }); 24 });
......
...@@ -7,12 +7,13 @@ describe("준비", () => { ...@@ -7,12 +7,13 @@ describe("준비", () => {
7 it("방에 입장하면 준비되지 않은 상태입니다", () => { 7 it("방에 입장하면 준비되지 않은 상태입니다", () => {
8 const { 8 const {
9 sockets: [socket], 9 sockets: [socket],
10 + users: [user],
10 rooms: [room], 11 rooms: [room],
11 } = prepareUsersEmptyRooms(1, 1); 12 } = prepareUsersEmptyRooms(1, 1);
12 13
13 const response = socket.test("joinRoom", { uuid: room.uuid }); 14 const response = socket.test("joinRoom", { uuid: room.uuid });
14 expect(response.ok).eq(true); 15 expect(response.ok).eq(true);
15 - expect(response.result?.users[0]?.username).eq("guest1"); 16 + expect(response.result?.users[0]?.nickname).eq(user.nickname);
16 expect(response.result?.users[0]?.ready).eq(false); 17 expect(response.result?.users[0]?.ready).eq(false);
17 }); 18 });
18 it("준비 상태를 설정합니다", () => { 19 it("준비 상태를 설정합니다", () => {
...@@ -26,25 +27,19 @@ describe("준비", () => { ...@@ -26,25 +27,19 @@ describe("준비", () => {
26 27
27 socket.testOk("ready", { ready: true }); 28 socket.testOk("ready", { ready: true });
28 expect(room.isReady(user)).eq(true); 29 expect(room.isReady(user)).eq(true);
29 - expect(socket.socket.received("updateRoomUser")).deep.eq({ 30 +
30 - state: "updated", 31 + let response = socket.socket.received("updateRoomUser");
31 - user: { 32 + expect(response.state).eq("updated");
32 - username: user.username, 33 + expect(response.user.nickname).eq(user.nickname);
33 - admin: false, 34 + expect(response.user.ready).eq(true);
34 - ready: true,
35 - },
36 - });
37 35
38 socket.testOk("ready", { ready: false }); 36 socket.testOk("ready", { ready: false });
39 expect(room.isReady(user)).eq(false); 37 expect(room.isReady(user)).eq(false);
40 - expect(socket.socket.received("updateRoomUser")).deep.eq({ 38 +
41 - state: "updated", 39 + response = socket.socket.received("updateRoomUser");
42 - user: { 40 + expect(response.state).eq("updated");
43 - username: user.username, 41 + expect(response.user.nickname).eq(user.nickname);
44 - admin: false, 42 + expect(response.user.ready).eq(false);
45 - ready: false,
46 - },
47 - });
48 }); 43 });
49 it("방장은 준비할 수 없습니다", () => { 44 it("방장은 준비할 수 없습니다", () => {
50 const { 45 const {
......
...@@ -49,8 +49,8 @@ export class SocketTester { ...@@ -49,8 +49,8 @@ export class SocketTester {
49 return this.connection.handleRaw(obj); 49 return this.connection.handleRaw(obj);
50 } 50 }
51 51
52 - public login(username: string): void { 52 + public login(nickname: string): void {
53 - this.testOk("login", { username }); 53 + this.testOk("login", { nickname });
54 expect(this.connection.user !== undefined).eq(true); 54 expect(this.connection.user !== undefined).eq(true);
55 } 55 }
56 56
......