Spaces:
Runtime error
Runtime error
Added unit/mock testing
Browse files- server/src/socket/routes.ts +1 -1
- server/src/socket/routes/{send_vibration.ts → send_touch.ts} +0 -0
- server/test/helpers.spec.ts +1 -1
- server/test/index.spec.ts +1 -1
- server/test/socket/hapticLinkServer.spec.ts +1 -1
- server/test/socket/room.spec.ts +1 -2
- server/test/socket/router.spec.ts +37 -0
- server/test/socket/routes/join_room.spec.ts +61 -0
- server/test/socket/routes/leave_room.spec.ts +52 -0
- server/test/socket/routes/send_touch.spec.ts +75 -0
- server/test/socket/routes/set_username.spec.ts +30 -0
- server/test/socket/routes/test_connection.spec.ts +28 -0
server/src/socket/routes.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import { HapticLinkServer } from "./hapticLinkServer";
|
| 2 |
import { JoinRoomHandler, JoinRoomSchema } from "./routes/join_room";
|
| 3 |
import { LeaveRoomHandler, LeaveRoomSchema } from "./routes/leave_room";
|
| 4 |
-
import { SendVibrationHandler, SendVibrationSchema } from "./routes/
|
| 5 |
import { SetUsernameHandler, SetUsernameSchema } from "./routes/set_username";
|
| 6 |
import { TestConnnectionSchema, TestConnectionHandler } from "./routes/test_connection";
|
| 7 |
|
|
|
|
| 1 |
import { HapticLinkServer } from "./hapticLinkServer";
|
| 2 |
import { JoinRoomHandler, JoinRoomSchema } from "./routes/join_room";
|
| 3 |
import { LeaveRoomHandler, LeaveRoomSchema } from "./routes/leave_room";
|
| 4 |
+
import { SendVibrationHandler, SendVibrationSchema } from "./routes/send_touch";
|
| 5 |
import { SetUsernameHandler, SetUsernameSchema } from "./routes/set_username";
|
| 6 |
import { TestConnnectionSchema, TestConnectionHandler } from "./routes/test_connection";
|
| 7 |
|
server/src/socket/routes/{send_vibration.ts → send_touch.ts}
RENAMED
|
File without changes
|
server/test/helpers.spec.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import { expect } from 'chai';
|
| 2 |
import { generateSessionToken } from '../src/helpers';
|
| 3 |
|
| 4 |
-
describe('
|
| 5 |
it('should generate a token of a correct length', () => {
|
| 6 |
const length = 16; // Specify the length of the token to generate
|
| 7 |
const token = generateSessionToken(length);
|
|
|
|
| 1 |
import { expect } from 'chai';
|
| 2 |
import { generateSessionToken } from '../src/helpers';
|
| 3 |
|
| 4 |
+
describe('Helpers', () => {
|
| 5 |
it('should generate a token of a correct length', () => {
|
| 6 |
const length = 16; // Specify the length of the token to generate
|
| 7 |
const token = generateSessionToken(length);
|
server/test/index.spec.ts
CHANGED
|
@@ -61,7 +61,7 @@ describe('WebSocket Server', function() {
|
|
| 61 |
|
| 62 |
});
|
| 63 |
|
| 64 |
-
it('
|
| 65 |
// Listen for messages from the server
|
| 66 |
wsClient.on('message', (data: string) => {
|
| 67 |
expect(JSON.parse(data).message).to.equal("test_connection_response");
|
|
|
|
| 61 |
|
| 62 |
});
|
| 63 |
|
| 64 |
+
it('should start, listen, and respond to test_connection', (done) => {
|
| 65 |
// Listen for messages from the server
|
| 66 |
wsClient.on('message', (data: string) => {
|
| 67 |
expect(JSON.parse(data).message).to.equal("test_connection_response");
|
server/test/socket/hapticLinkServer.spec.ts
CHANGED
|
@@ -33,7 +33,7 @@ describe("Haptic Link Server", function() {
|
|
| 33 |
|
| 34 |
})
|
| 35 |
|
| 36 |
-
it("
|
| 37 |
if (!server.users || server.users.size != 0) {
|
| 38 |
return done("users map not initialized correctly")
|
| 39 |
}
|
|
|
|
| 33 |
|
| 34 |
})
|
| 35 |
|
| 36 |
+
it("should initialize", (done) => {
|
| 37 |
if (!server.users || server.users.size != 0) {
|
| 38 |
return done("users map not initialized correctly")
|
| 39 |
}
|
server/test/socket/room.spec.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
| 1 |
import { expect } from "chai";
|
| 2 |
-
import {
|
| 3 |
import { Room } from "../../src/socket/room";
|
| 4 |
import {WebSocketWrapper} from "./hapticLinkServer.spec";
|
| 5 |
|
| 6 |
describe("Rooms", function() {
|
| 7 |
-
let server: HapticLinkServer = new HapticLinkServer();
|
| 8 |
const ws1 = new WebSocketWrapper();
|
| 9 |
const ws2 = new WebSocketWrapper();
|
| 10 |
const user1: User = new User(ws1);
|
|
|
|
| 1 |
import { expect } from "chai";
|
| 2 |
+
import { User } from "../../src/socket/hapticLinkServer";
|
| 3 |
import { Room } from "../../src/socket/room";
|
| 4 |
import {WebSocketWrapper} from "./hapticLinkServer.spec";
|
| 5 |
|
| 6 |
describe("Rooms", function() {
|
|
|
|
| 7 |
const ws1 = new WebSocketWrapper();
|
| 8 |
const ws2 = new WebSocketWrapper();
|
| 9 |
const user1: User = new User(ws1);
|
server/test/socket/router.spec.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { readdirSync } from "fs";
|
| 2 |
+
import { HapticLinkServer } from "../../src/socket/hapticLinkServer"
|
| 3 |
+
import { registerRoutes } from "../../src/socket/routes";
|
| 4 |
+
import { expect } from 'chai';
|
| 5 |
+
import { resolve } from "path";
|
| 6 |
+
|
| 7 |
+
describe("Router", () => {
|
| 8 |
+
let server: HapticLinkServer = new HapticLinkServer();
|
| 9 |
+
|
| 10 |
+
beforeEach(() => {
|
| 11 |
+
server = new HapticLinkServer();
|
| 12 |
+
})
|
| 13 |
+
|
| 14 |
+
it("should add routes", (done) => {
|
| 15 |
+
registerRoutes(server);
|
| 16 |
+
|
| 17 |
+
const files = readdirSync(resolve("src/socket/routes"));
|
| 18 |
+
const routes: string[] = [];
|
| 19 |
+
files.forEach(file => {
|
| 20 |
+
if (file.startsWith("_")) return;
|
| 21 |
+
routes.push(file.replace(".ts", ""));
|
| 22 |
+
});
|
| 23 |
+
|
| 24 |
+
const registeredRoutes = Object.keys(server.routes);
|
| 25 |
+
const missingRoutes: string[] = []
|
| 26 |
+
|
| 27 |
+
routes.forEach(route => {
|
| 28 |
+
if (!registeredRoutes.includes(route)) {
|
| 29 |
+
missingRoutes.push(route)
|
| 30 |
+
}
|
| 31 |
+
})
|
| 32 |
+
|
| 33 |
+
expect(missingRoutes.length).to.equal(0, "routes not registered: " + missingRoutes);
|
| 34 |
+
done();
|
| 35 |
+
})
|
| 36 |
+
|
| 37 |
+
})
|
server/test/socket/routes/join_room.spec.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { expect } from "chai";
|
| 2 |
+
import { Context, HapticLinkServer, User } from "../../../src/socket/hapticLinkServer";
|
| 3 |
+
import { JoinRoomHandler, JoinRoomPayload } from "../../../src/socket/routes/join_room";
|
| 4 |
+
import { WebSocketWrapper } from "../hapticLinkServer.spec";
|
| 5 |
+
|
| 6 |
+
describe("Join Room", () => {
|
| 7 |
+
let server: HapticLinkServer;
|
| 8 |
+
let ws: WebSocketWrapper;
|
| 9 |
+
let user: User;
|
| 10 |
+
let ws2: WebSocketWrapper;
|
| 11 |
+
let user2: User;
|
| 12 |
+
let ctx: Context<JoinRoomPayload>;
|
| 13 |
+
|
| 14 |
+
beforeEach(() => {
|
| 15 |
+
server = new HapticLinkServer();
|
| 16 |
+
ws = new WebSocketWrapper();
|
| 17 |
+
user = new User(ws);
|
| 18 |
+
ws2 = new WebSocketWrapper();
|
| 19 |
+
user2 = new User(ws2);
|
| 20 |
+
ctx = {
|
| 21 |
+
ws: ws,
|
| 22 |
+
user: user,
|
| 23 |
+
payload: { username: "test" },
|
| 24 |
+
server: server,
|
| 25 |
+
};
|
| 26 |
+
});
|
| 27 |
+
|
| 28 |
+
function testJoinRoom(expectedUserCount: number) {
|
| 29 |
+
JoinRoomHandler(ctx);
|
| 30 |
+
const resData = (ws.sendData as string);
|
| 31 |
+
const res = JSON.parse(resData);
|
| 32 |
+
ws.sendData = "";
|
| 33 |
+
if (!ctx.payload.roomId) {
|
| 34 |
+
ctx.payload.roomId = res.roomId; // Store room ID if not set (for new rooms)
|
| 35 |
+
}
|
| 36 |
+
expect(res.message).to.equal("room_update", "room update not broadcasted");
|
| 37 |
+
expect(res.users.length).to.equal(expectedUserCount, "user quantity mismatch");
|
| 38 |
+
expect(server.rooms[res.roomId].users.length).to.equal(expectedUserCount, "server user quantity mismatch");
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
it("should join a newly created room", () => {
|
| 42 |
+
testJoinRoom(1);
|
| 43 |
+
expect(ctx.payload.roomId!).to.satisfy((id: string) => id.length > 3, "room id not generated");
|
| 44 |
+
expect(user.username).to.equal("test", "didn't set username");
|
| 45 |
+
});
|
| 46 |
+
|
| 47 |
+
it("should join existing room", () => {
|
| 48 |
+
testJoinRoom(1); // Initial user joins and creates room
|
| 49 |
+
|
| 50 |
+
// Set up second user to join the same room
|
| 51 |
+
ctx.payload.username = "test2";
|
| 52 |
+
ctx.user = user2;
|
| 53 |
+
ctx.ws = ws2;
|
| 54 |
+
|
| 55 |
+
testJoinRoom(2); // Second user joins the existing room
|
| 56 |
+
|
| 57 |
+
// Attempt to join the same user again and test if user size remains unchanged
|
| 58 |
+
JoinRoomHandler(ctx);
|
| 59 |
+
expect(server.rooms[ctx.payload.roomId!].users.length).to.equal(2, "user joined twice");
|
| 60 |
+
});
|
| 61 |
+
});
|
server/test/socket/routes/leave_room.spec.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { expect } from "chai";
|
| 2 |
+
import { Context, HapticLinkServer, User } from "../../../src/socket/hapticLinkServer";
|
| 3 |
+
import { JoinRoomHandler, JoinRoomPayload } from "../../../src/socket/routes/join_room";
|
| 4 |
+
import { WebSocketWrapper } from "../hapticLinkServer.spec";
|
| 5 |
+
import { LeaveRoomHandler, LeaveRoomPayload } from "../../../src/socket/routes/leave_room";
|
| 6 |
+
|
| 7 |
+
describe("Leave Room", () => {
|
| 8 |
+
let server: HapticLinkServer;
|
| 9 |
+
let ws: WebSocketWrapper;
|
| 10 |
+
let user: User;
|
| 11 |
+
let ws2: WebSocketWrapper;
|
| 12 |
+
let user2: User;
|
| 13 |
+
let ctx: Context<JoinRoomPayload>;
|
| 14 |
+
let ctx2: Context<LeaveRoomPayload>;
|
| 15 |
+
|
| 16 |
+
beforeEach(() => {
|
| 17 |
+
server = new HapticLinkServer();
|
| 18 |
+
ws = new WebSocketWrapper();
|
| 19 |
+
user = new User(ws);
|
| 20 |
+
ws2 = new WebSocketWrapper();
|
| 21 |
+
user2 = new User(ws2);
|
| 22 |
+
ctx = {
|
| 23 |
+
ws: ws,
|
| 24 |
+
user: user,
|
| 25 |
+
payload: { username: "test" },
|
| 26 |
+
server: server,
|
| 27 |
+
};
|
| 28 |
+
ctx2 = {
|
| 29 |
+
ws: ws,
|
| 30 |
+
user: user,
|
| 31 |
+
payload: { roomId: "" },
|
| 32 |
+
server: server,
|
| 33 |
+
};
|
| 34 |
+
});
|
| 35 |
+
|
| 36 |
+
function testJoinRoom() {
|
| 37 |
+
JoinRoomHandler(ctx);
|
| 38 |
+
const resData = (ws.sendData as string);
|
| 39 |
+
const res = JSON.parse(resData);
|
| 40 |
+
ws.sendData = "";
|
| 41 |
+
if (!ctx.payload.roomId) {
|
| 42 |
+
ctx.payload.roomId = res.roomId; // Store room ID if not set (for new rooms)
|
| 43 |
+
}
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
it("should leave room", () => {
|
| 47 |
+
testJoinRoom();
|
| 48 |
+
ctx2.payload.roomId = ctx.payload.roomId!;
|
| 49 |
+
LeaveRoomHandler(ctx2)
|
| 50 |
+
expect(server.rooms[ctx2.payload.roomId].users.length).to.equal(0, "user wasn't removed from room");
|
| 51 |
+
});
|
| 52 |
+
});
|
server/test/socket/routes/send_touch.spec.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import { expect } from "chai";
|
| 3 |
+
import { Context, HapticLinkServer, User } from "../../../src/socket/hapticLinkServer";
|
| 4 |
+
import { JoinRoomHandler, JoinRoomPayload } from "../../../src/socket/routes/join_room";
|
| 5 |
+
import { WebSocketWrapper } from "../hapticLinkServer.spec";
|
| 6 |
+
import { SendVibrationHandler, SendVibrationPayload } from "../../../src/socket/routes/send_touch";
|
| 7 |
+
|
| 8 |
+
describe("Send Vibration", () => {
|
| 9 |
+
let server: HapticLinkServer;
|
| 10 |
+
let ws: WebSocketWrapper;
|
| 11 |
+
let user: User;
|
| 12 |
+
let ws2: WebSocketWrapper;
|
| 13 |
+
let user2: User;
|
| 14 |
+
let ctx: Context<JoinRoomPayload>;
|
| 15 |
+
let ctx2: Context<JoinRoomPayload>;
|
| 16 |
+
let ctx3: Context<SendVibrationPayload>;
|
| 17 |
+
|
| 18 |
+
beforeEach(() => {
|
| 19 |
+
server = new HapticLinkServer();
|
| 20 |
+
ws = new WebSocketWrapper();
|
| 21 |
+
user = new User(ws);
|
| 22 |
+
ws2 = new WebSocketWrapper();
|
| 23 |
+
user2 = new User(ws2);
|
| 24 |
+
ctx = {
|
| 25 |
+
ws: ws,
|
| 26 |
+
user: user,
|
| 27 |
+
payload: { username: "test", roomId: "testRoom" },
|
| 28 |
+
server: server,
|
| 29 |
+
};
|
| 30 |
+
ctx2 = {
|
| 31 |
+
ws: ws2,
|
| 32 |
+
user: user2,
|
| 33 |
+
payload: { username: "test2", roomId: "testRoom" },
|
| 34 |
+
server: server,
|
| 35 |
+
};
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
ctx3 = {
|
| 39 |
+
ws: ws,
|
| 40 |
+
user: user,
|
| 41 |
+
server: server,
|
| 42 |
+
payload: {
|
| 43 |
+
id: 1,
|
| 44 |
+
type: "enabled",
|
| 45 |
+
position: {
|
| 46 |
+
x: 3,
|
| 47 |
+
y: 10,
|
| 48 |
+
},
|
| 49 |
+
color: "#FFF",
|
| 50 |
+
intensity: 1,
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
});
|
| 54 |
+
|
| 55 |
+
it("should broadcast vibration", () => {
|
| 56 |
+
JoinRoomHandler(ctx)
|
| 57 |
+
JoinRoomHandler(ctx2)
|
| 58 |
+
ws.sendData = "";
|
| 59 |
+
ws2.sendData = "";
|
| 60 |
+
SendVibrationHandler(ctx3);
|
| 61 |
+
|
| 62 |
+
const res = JSON.parse(ws2.sendData as string)
|
| 63 |
+
|
| 64 |
+
expect(ws.sendData).to.equal(ws2.sendData, "vibration wasn't broadcasted correctly");
|
| 65 |
+
expect(res.message).to.equal("receive_touch", "invalid response");
|
| 66 |
+
expect(res.id).to.equal(user.id + "_" + "1", "invalid touch id");
|
| 67 |
+
expect(res.type).to.equal("enabled", "invalid touch type");
|
| 68 |
+
expect(res.user.username).to.equal("test", "wrong username");
|
| 69 |
+
expect(res.user.id).to.equal(user.id, "wrong user id");
|
| 70 |
+
expect(res.position.x).to.equal(3, "wrong x position");
|
| 71 |
+
expect(res.position.y).to.equal(10, "wrong y position");
|
| 72 |
+
expect(res.color).to.equal("#FFF", "wrong color");
|
| 73 |
+
expect(res.intensity).to.equal(1, "wrong intensity");
|
| 74 |
+
});
|
| 75 |
+
});
|
server/test/socket/routes/set_username.spec.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { expect } from "chai";
|
| 2 |
+
import { Context, HapticLinkServer, User } from "../../../src/socket/hapticLinkServer";
|
| 3 |
+
import { SetUsernameHandler, SetUsernamePayload } from "../../../src/socket/routes/set_username";
|
| 4 |
+
import { WebSocketWrapper } from "../hapticLinkServer.spec";
|
| 5 |
+
|
| 6 |
+
describe("Set Username", () => {
|
| 7 |
+
let server: HapticLinkServer;
|
| 8 |
+
let ws: WebSocketWrapper;
|
| 9 |
+
let user: User;
|
| 10 |
+
let ctx: Context<SetUsernamePayload>;
|
| 11 |
+
|
| 12 |
+
beforeEach(() => {
|
| 13 |
+
server = new HapticLinkServer();
|
| 14 |
+
ws = new WebSocketWrapper();
|
| 15 |
+
user = new User(ws);
|
| 16 |
+
user.username = "old username"
|
| 17 |
+
ctx = {
|
| 18 |
+
ws: ws,
|
| 19 |
+
user: user,
|
| 20 |
+
payload: { username: "new username" },
|
| 21 |
+
server: server,
|
| 22 |
+
};
|
| 23 |
+
});
|
| 24 |
+
|
| 25 |
+
it("should change username", (done) => {
|
| 26 |
+
SetUsernameHandler(ctx);
|
| 27 |
+
expect(user.username).to.equal("new username", "name wasn't changed correctly")
|
| 28 |
+
done();
|
| 29 |
+
})
|
| 30 |
+
})
|
server/test/socket/routes/test_connection.spec.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { expect } from "chai";
|
| 2 |
+
import { Context, HapticLinkServer, User } from "../../../src/socket/hapticLinkServer"
|
| 3 |
+
import { TestConnectionHandler, TestConnectionPayload } from "../../../src/socket/routes/test_connection"
|
| 4 |
+
import { WebSocketWrapper } from "../hapticLinkServer.spec";
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
describe("Test Connection", () => {
|
| 8 |
+
let server: HapticLinkServer = new HapticLinkServer();
|
| 9 |
+
const ws = new WebSocketWrapper();
|
| 10 |
+
const user = new User(ws);
|
| 11 |
+
user.username = "test"
|
| 12 |
+
let ctx: Context<TestConnectionPayload> = {
|
| 13 |
+
ws: ws,
|
| 14 |
+
user: user,
|
| 15 |
+
payload: {
|
| 16 |
+
route: "test_connection",
|
| 17 |
+
},
|
| 18 |
+
server: server,
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
it("should return connection response with user", (done) => {
|
| 22 |
+
TestConnectionHandler(ctx);
|
| 23 |
+
const res = JSON.parse(ws.sendData as string);
|
| 24 |
+
expect(res.message).to.equal("test_connection_response", "didn't return message")
|
| 25 |
+
expect(res.username).to.equal("test", "didn't return message")
|
| 26 |
+
done();
|
| 27 |
+
})
|
| 28 |
+
})
|