chat.test.ts
2.7 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { expect } from "chai";
import { RoomManager } from "../room/RoomManager";
import { DummySocket } from "./util/DummySocket";
import { SocketTester } from "./util/SocketTester";
describe("채팅", () => {
const roomManager = new RoomManager();
it("로그인하지 않은 유저는 요청할 수 없습니다", () => {
const socket = new SocketTester(roomManager);
const response = socket.test("chat", { message: "Hello World" });
expect(response.ok).eq(false);
});
it("방에 접속하지 않은 유저는 요청할 수 없습니다", () => {
const socket = new SocketTester(roomManager);
socket.login("guest");
const response = socket.test("chat", { message: "Hello World" });
expect(response.ok).eq(false);
});
it("채팅을 보냅니다", () => {
const socket = new SocketTester(roomManager);
socket.login("guest");
const room = roomManager.create("테스트", 2);
expect(socket.test("joinRoom", { uuid: room.uuid }).ok).eq(true);
expect(socket.test("chat", { message: "Hello World" }).ok).eq(true);
});
it("자신을 제외한 다른 사람들이 채팅을 받습니다", () => {
const socket1 = new SocketTester(roomManager);
socket1.login("guest1");
const socket2 = new SocketTester(roomManager);
socket2.login("guest2");
const room = roomManager.create("테스트", 2);
expect(socket1.test("joinRoom", { uuid: room.uuid }).ok).eq(true);
expect(socket2.test("joinRoom", { uuid: room.uuid }).ok).eq(true);
expect(socket1.test("chat", { message: "Hello World" }).ok).eq(true);
expect(socket2.socket.received("chat").message).eq("Hello World");
expect(socket2.socket.received("chat").sender).eq("guest1");
socket1.socket.notReceived("chat");
});
it("빈 채팅은 보낼 수 없습니다", () => {
const socket = new SocketTester(roomManager);
socket.login("guest");
const room = roomManager.create("테스트", 2);
expect(socket.test("joinRoom", { uuid: room.uuid }).ok).eq(true);
expect(socket.test("chat", { message: "" }).ok).eq(false);
expect(socket.test("chat", { message: " " }).ok).eq(false);
});
it("글자수가 300자를 넘는 채팅은 보낼 수 없습니다", () => {
const socket = new SocketTester(roomManager);
socket.login("guest");
const room = roomManager.create("테스트", 2);
expect(socket.test("joinRoom", { uuid: room.uuid }).ok).eq(true);
expect(socket.test("chat", { message: "A".repeat(300) }).ok).eq(true);
expect(socket.test("chat", { message: "A".repeat(301) }).ok).eq(false);
expect(socket.test("chat", { message: "가".repeat(300) }).ok).eq(true);
expect(socket.test("chat", { message: "가".repeat(301) }).ok).eq(false);
});
});