SocketTester.ts
1.03 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
import {
RawMessage,
ServerInboundMessage,
ServerInboundMessageKey,
ServerResponse,
} from "../../../common";
import { Connection } from "../../connection/Connection";
import { RoomManager } from "../../room/RoomManager";
import { DummySocket } from "./DummySocket";
export class SocketTester {
public readonly connection: Connection;
public readonly socket: DummySocket;
constructor(roomManager: RoomManager) {
this.socket = new DummySocket();
this.connection = new Connection(this.socket, roomManager);
}
public test<T extends ServerInboundMessageKey>(
type: T,
message: ServerInboundMessage<T>
): ServerResponse<any> {
return this.connection.handleRaw({
type: type as string,
message: message,
});
}
public testRaw(raw: RawMessage): ServerResponse<any> {
return this.connection.handleRaw(raw);
}
public testAny(obj: any): ServerResponse<any> {
return this.connection.handleRaw(obj);
}
public login(username: string): void {
this.test("login", { username });
}
}