BIG WIP of refactoring my work in TS
This commit is contained in:
parent
af5d2a5a97
commit
fbfc208129
12 changed files with 274 additions and 11 deletions
|
@ -3,27 +3,27 @@ import {Message} from "../src/Model/Websocket/Message";
|
|||
|
||||
describe("Message Model", () => {
|
||||
it("should find userId and roomId", () => {
|
||||
let message = JSON.stringify({userId: "test1", roomId: "test2"});
|
||||
let message = {userId: "test1", roomId: "test2"};
|
||||
let messageObject = new Message(message);
|
||||
expect(messageObject.userId).toBe("test1");
|
||||
expect(messageObject.roomId).toBe("test2");
|
||||
})
|
||||
|
||||
it("should expose a toJson method", () => {
|
||||
let message = JSON.stringify({userId: "test1", roomId: "test2"});
|
||||
let message = {userId: "test1", roomId: "test2"};
|
||||
let messageObject = new Message(message);
|
||||
expect(messageObject.toJson()).toEqual({userId: "test1", roomId: "test2"});
|
||||
})
|
||||
|
||||
it("should find throw error when no userId", () => {
|
||||
let message = JSON.stringify({roomId: "test2"});
|
||||
let message = {roomId: "test2"};
|
||||
expect(() => {
|
||||
let messageObject = new Message(message);
|
||||
}).toThrow(new Error("userId or roomId cannot be null"));
|
||||
})
|
||||
|
||||
it("should find throw error when no roomId", () => {
|
||||
let message = JSON.stringify({userId: "test1"});
|
||||
let message = {userId: "test1"};
|
||||
expect(() => {
|
||||
let messageObject = new Message(message);
|
||||
}).toThrow(new Error("userId or roomId cannot be null"));
|
||||
|
|
39
back/tests/WorldTest.ts
Normal file
39
back/tests/WorldTest.ts
Normal file
|
@ -0,0 +1,39 @@
|
|||
import "jasmine";
|
||||
import {Message} from "../src/Model/Websocket/Message";
|
||||
import {World} from "../src/Model/World";
|
||||
import {MessageUserPosition, Point} from "../src/Model/Websocket/MessageUserPosition";
|
||||
|
||||
describe("World", () => {
|
||||
it("should connect user1 and user2", () => {
|
||||
let connectCalled: boolean = false;
|
||||
let connect = (user1: string, user2: string): void => {
|
||||
connectCalled = true;
|
||||
}
|
||||
let disconnect = (user1: string, user2: string): void => {
|
||||
|
||||
}
|
||||
|
||||
let world = new World(connect, disconnect);
|
||||
|
||||
world.join(new MessageUserPosition({
|
||||
userId: "foo",
|
||||
roomId: 1,
|
||||
position: new Point(100, 100)
|
||||
}));
|
||||
|
||||
world.join(new MessageUserPosition({
|
||||
userId: "bar",
|
||||
roomId: 1,
|
||||
position: new Point(500, 100)
|
||||
}));
|
||||
|
||||
world.updatePosition(new MessageUserPosition({
|
||||
userId: "bar",
|
||||
roomId: 1,
|
||||
position: new Point(101, 100)
|
||||
}));
|
||||
|
||||
expect(connectCalled).toBe(true);
|
||||
|
||||
})
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue