workadventure/back/tests/MessageTest.ts
David Négrier 492196b333 Cleanup: renaming "frame" to "character"
The "frame" variable actually contains a string pointing to the character selected.
It has nothing to do with a frame which is usually a particular image in an animation.

I'm renaming the variable accross the application to avoid confusion.
2020-05-08 15:18:22 +02:00

41 lines
1.5 KiB
TypeScript

import "jasmine";
import {Message} from "../src/Model/Websocket/Message";
describe("Message Model", () => {
it("should find userId and roomId", () => {
let message = {userId: "test1", roomId: "test2", name: "foo", frame: "user"};
let messageObject = new Message(message);
expect(messageObject.userId).toBe("test1");
expect(messageObject.roomId).toBe("test2");
expect(messageObject.name).toBe("foo");
expect(messageObject.character).toBe("user");
})
it("should expose a toJson method", () => {
let message = {userId: "test1", roomId: "test2", name: "foo", frame: "user"};
let messageObject = new Message(message);
expect(messageObject.toJson()).toEqual({userId: "test1", roomId: "test2", name: "foo", frame: "user"});
});
it("should find throw error when no userId", () => {
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 = {userId: "test1"};
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 = {name: "foo"};
expect(() => {
let messageObject = new Message(message);
}).toThrow(new Error("userId or roomId cannot be null"));
});
})