added jasmine in the back

This commit is contained in:
kharhamel 2020-04-06 15:48:19 +02:00
parent f7434ba64a
commit ded19549c7
7 changed files with 69 additions and 8 deletions

View file

@ -61,3 +61,7 @@ jobs:
- name: "Lint"
run: yarn run lint
working-directory: "back"
- name: "Jasmine"
run: yarn test
working-directory: "back"

5
back/jasmine.json Normal file
View file

@ -0,0 +1,5 @@
{
"spec_dir": "tests",
"spec_files": ["**/*[tT]est.ts"],
"stopSpecOnExpectationFailure": false
}

View file

@ -7,6 +7,7 @@
"tsc": "tsc",
"dev": "ts-node-dev --respawn --transpileOnly ./server.ts",
"prod": "tsc && node ./dist/server.js",
"test": "ts-node node_modules/jasmine/bin/jasmine --config=jasmine.json",
"lint": "node_modules/.bin/eslint src/ . --ext .ts"
},
"repository": {
@ -33,8 +34,10 @@
"typescript": "^3.8.3"
},
"devDependencies": {
"@types/jasmine": "^3.5.10",
"@typescript-eslint/eslint-plugin": "^2.26.0",
"@typescript-eslint/parser": "^2.26.0",
"eslint": "^6.8.0"
"eslint": "^6.8.0",
"jasmine": "^3.5.0"
}
}

View file

@ -16,14 +16,14 @@ let RefreshUserPositionFunction = function(rooms : ExtRooms, Io: socketIO.Server
//create mapping with all users in all rooms
let mapPositionUserByRoom = new Map();
for(let i = 0; i < socketsKey.length; i++){
let socket = clients.sockets[socketsKey[i]];
if(!(socket as ExSocketInterface).position){
let socket = clients.sockets[socketsKey[i]] as ExSocketInterface;
if(!socket.position){
continue;
}
let data = {
userId : (socket as ExSocketInterface).userId,
roomId : (socket as ExSocketInterface).roomId,
position : (socket as ExSocketInterface).position,
userId : socket.userId,
roomId : socket.roomId,
position : socket.position,
};
let dataArray = <any>[];
if(mapPositionUserByRoom.get(data.roomId)){

View file

@ -5,7 +5,7 @@ export class Message {
constructor(message: string) {
let data = JSON.parse(message);
if(!data.userId || !data.roomId){
throw Error("userId and roomId cannot be null");
throw Error("userId or roomId cannot be null");
}
this.userId = data.userId;
this.roomId = data.roomId;

31
back/tests/MessageTest.ts Normal file
View file

@ -0,0 +1,31 @@
import "jasmine";
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 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 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"});
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"});
expect(() => {
let messageObject = new Message(message);
}).toThrow(new Error("userId or roomId cannot be null"));
})
})

View file

@ -73,6 +73,11 @@
dependencies:
http-status-codes "*"
"@types/jasmine@^3.5.10":
version "3.5.10"
resolved "https://registry.yarnpkg.com/@types/jasmine/-/jasmine-3.5.10.tgz#a1a41012012b5da9d4b205ba9eba58f6cce2ab7b"
integrity sha512-3F8qpwBAiVc5+HPJeXJpbrl+XjawGmciN5LgiO7Gv1pl1RHtjoMNqZpqEksaPJW05ViKe8snYInRs6xB25Xdew==
"@types/json-schema@^7.0.3":
version "7.0.4"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.4.tgz#38fd73ddfd9b55abb1e1b2ed578cb55bd7b7d339"
@ -915,7 +920,7 @@ glob-parent@^5.0.0:
dependencies:
is-glob "^4.0.1"
glob@^7.1.3, glob@^7.1.6:
glob@^7.1.3, glob@^7.1.4, glob@^7.1.6:
version "7.1.6"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6"
integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==
@ -1134,6 +1139,19 @@ isexe@^2.0.0:
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=
jasmine-core@~3.5.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/jasmine-core/-/jasmine-core-3.5.0.tgz#132c23e645af96d85c8bca13c8758b18429fc1e4"
integrity sha512-nCeAiw37MIMA9w9IXso7bRaLl+c/ef3wnxsoSAlYrzS+Ot0zTG6nU8G/cIfGkqpkjX2wNaIW9RFG0TwIFnG6bA==
jasmine@^3.5.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/jasmine/-/jasmine-3.5.0.tgz#7101eabfd043a1fc82ac24e0ab6ec56081357f9e"
integrity sha512-DYypSryORqzsGoMazemIHUfMkXM7I7easFaxAvNM3Mr6Xz3Fy36TupTrAOxZWN8MVKEU5xECv22J4tUQf3uBzQ==
dependencies:
glob "^7.1.4"
jasmine-core "~3.5.0"
js-tokens@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"