admin.test.ts
1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { expect } from "chai";
import { RoomManager } from "../room/RoomManager";
import { SocketTester } from "./util/SocketTester";
describe("방장", () => {
const roomManager = new RoomManager();
it("방을 만든 유저가 방장이 됩니다", () => {
const socket = new SocketTester(roomManager);
socket.login("guest");
expect(socket.connection.user !== undefined).eq(true);
const room = roomManager.create("테스트", 2, socket.connection.user);
expect(room.admin).eq(socket.connection.user);
});
it("나중에 들어온 유저는 방장이 되지 않습니다", () => {
const socket1 = new SocketTester(roomManager);
const socket2 = new SocketTester(roomManager);
socket1.login("guest1");
socket2.login("guest2");
expect(socket1.connection.user !== undefined).eq(true);
expect(socket2.connection.user !== undefined).eq(true);
const room = roomManager.create("테스트", 2, socket1.connection.user);
const response = socket2.test("joinRoom", { uuid: room.uuid });
expect(response.ok).eq(true);
expect(room.admin).eq(socket1.connection.user);
expect(room.admin).not.eq(socket2.connection.user);
expect(response.result?.users[0]?.username).eq("guest1");
expect(response.result?.users[0]?.admin).eq(true);
});
it("방장이 나가면 방장이 인계됩니다", () => {
const socket1 = new SocketTester(roomManager);
const socket2 = new SocketTester(roomManager);
socket1.login("guest1");
socket2.login("guest2");
expect(socket1.connection.user !== undefined).eq(true);
expect(socket2.connection.user !== undefined).eq(true);
const room = roomManager.create("테스트", 2, socket1.connection.user);
expect(socket2.test("joinRoom", { uuid: room.uuid }).ok).eq(true);
expect(room.admin).eq(socket1.connection.user);
expect(room.admin).not.eq(socket2.connection.user);
expect(socket1.test("leaveRoom", {}).ok).eq(true);
expect(room.admin).eq(socket2.connection.user);
});
});