2020-04-06 15:48:19 +02:00
|
|
|
import "jasmine";
|
|
|
|
import {Message} from "../src/Model/Websocket/Message";
|
|
|
|
|
|
|
|
describe("Message Model", () => {
|
|
|
|
it("should find userId and roomId", () => {
|
2020-05-04 08:44:07 +02:00
|
|
|
let message = {userId: "test1", roomId: "test2", name: "foo"};
|
2020-04-06 15:48:19 +02:00
|
|
|
let messageObject = new Message(message);
|
|
|
|
expect(messageObject.userId).toBe("test1");
|
|
|
|
expect(messageObject.roomId).toBe("test2");
|
2020-05-04 08:44:07 +02:00
|
|
|
expect(messageObject.name).toBe("foo");
|
2020-04-06 15:48:19 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it("should expose a toJson method", () => {
|
2020-05-04 08:44:07 +02:00
|
|
|
let message = {userId: "test1", roomId: "test2", name: "foo"};
|
2020-04-06 15:48:19 +02:00
|
|
|
let messageObject = new Message(message);
|
2020-05-04 01:54:49 +02:00
|
|
|
expect(messageObject.toJson()).toEqual({userId: "test1", roomId: "test2", name: "foo"});
|
2020-04-06 15:48:19 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it("should find throw error when no userId", () => {
|
2020-04-07 10:08:04 +02:00
|
|
|
let message = {roomId: "test2"};
|
2020-04-06 15:48:19 +02:00
|
|
|
expect(() => {
|
|
|
|
let messageObject = new Message(message);
|
|
|
|
}).toThrow(new Error("userId or roomId cannot be null"));
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should find throw error when no roomId", () => {
|
2020-04-07 10:08:04 +02:00
|
|
|
let message = {userId: "test1"};
|
2020-04-06 15:48:19 +02:00
|
|
|
expect(() => {
|
|
|
|
let messageObject = new Message(message);
|
|
|
|
}).toThrow(new Error("userId or roomId cannot be null"));
|
|
|
|
})
|
2020-05-04 08:44:07 +02:00
|
|
|
|
|
|
|
it("should find throw error when no roomId", () => {
|
|
|
|
let message = {name: "foo"};
|
|
|
|
expect(() => {
|
|
|
|
let messageObject = new Message(message);
|
|
|
|
}).toThrow(new Error("userId or roomId cannot be null"));
|
|
|
|
})
|
2020-04-06 15:48:19 +02:00
|
|
|
})
|