Merge pull request #27 from Kharhamel/jasmine
added jasmine in the back
This commit is contained in:
commit
1b803cad20
4
.github/workflows/continuous_integration.yml
vendored
4
.github/workflows/continuous_integration.yml
vendored
@ -61,3 +61,7 @@ jobs:
|
|||||||
- name: "Lint"
|
- name: "Lint"
|
||||||
run: yarn run lint
|
run: yarn run lint
|
||||||
working-directory: "back"
|
working-directory: "back"
|
||||||
|
|
||||||
|
- name: "Jasmine"
|
||||||
|
run: yarn test
|
||||||
|
working-directory: "back"
|
||||||
|
5
back/jasmine.json
Normal file
5
back/jasmine.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"spec_dir": "tests",
|
||||||
|
"spec_files": ["**/*[tT]est.ts"],
|
||||||
|
"stopSpecOnExpectationFailure": false
|
||||||
|
}
|
@ -7,6 +7,7 @@
|
|||||||
"tsc": "tsc",
|
"tsc": "tsc",
|
||||||
"dev": "ts-node-dev --respawn --transpileOnly ./server.ts",
|
"dev": "ts-node-dev --respawn --transpileOnly ./server.ts",
|
||||||
"prod": "tsc && node ./dist/server.js",
|
"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"
|
"lint": "node_modules/.bin/eslint src/ . --ext .ts"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
@ -33,8 +34,10 @@
|
|||||||
"typescript": "^3.8.3"
|
"typescript": "^3.8.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/jasmine": "^3.5.10",
|
||||||
"@typescript-eslint/eslint-plugin": "^2.26.0",
|
"@typescript-eslint/eslint-plugin": "^2.26.0",
|
||||||
"@typescript-eslint/parser": "^2.26.0",
|
"@typescript-eslint/parser": "^2.26.0",
|
||||||
"eslint": "^6.8.0"
|
"eslint": "^6.8.0",
|
||||||
|
"jasmine": "^3.5.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,14 +16,14 @@ let RefreshUserPositionFunction = function(rooms : ExtRooms, Io: socketIO.Server
|
|||||||
//create mapping with all users in all rooms
|
//create mapping with all users in all rooms
|
||||||
let mapPositionUserByRoom = new Map();
|
let mapPositionUserByRoom = new Map();
|
||||||
for(let i = 0; i < socketsKey.length; i++){
|
for(let i = 0; i < socketsKey.length; i++){
|
||||||
let socket = clients.sockets[socketsKey[i]];
|
let socket = clients.sockets[socketsKey[i]] as ExSocketInterface;
|
||||||
if(!(socket as ExSocketInterface).position){
|
if(!socket.position){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let data = {
|
let data = {
|
||||||
userId : (socket as ExSocketInterface).userId,
|
userId : socket.userId,
|
||||||
roomId : (socket as ExSocketInterface).roomId,
|
roomId : socket.roomId,
|
||||||
position : (socket as ExSocketInterface).position,
|
position : socket.position,
|
||||||
};
|
};
|
||||||
let dataArray = <any>[];
|
let dataArray = <any>[];
|
||||||
if(mapPositionUserByRoom.get(data.roomId)){
|
if(mapPositionUserByRoom.get(data.roomId)){
|
||||||
|
@ -5,7 +5,7 @@ export class Message {
|
|||||||
constructor(message: string) {
|
constructor(message: string) {
|
||||||
let data = JSON.parse(message);
|
let data = JSON.parse(message);
|
||||||
if(!data.userId || !data.roomId){
|
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.userId = data.userId;
|
||||||
this.roomId = data.roomId;
|
this.roomId = data.roomId;
|
||||||
|
31
back/tests/MessageTest.ts
Normal file
31
back/tests/MessageTest.ts
Normal 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"));
|
||||||
|
})
|
||||||
|
})
|
@ -73,6 +73,11 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
http-status-codes "*"
|
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":
|
"@types/json-schema@^7.0.3":
|
||||||
version "7.0.4"
|
version "7.0.4"
|
||||||
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.4.tgz#38fd73ddfd9b55abb1e1b2ed578cb55bd7b7d339"
|
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:
|
dependencies:
|
||||||
is-glob "^4.0.1"
|
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"
|
version "7.1.6"
|
||||||
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6"
|
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6"
|
||||||
integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==
|
integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==
|
||||||
@ -1134,6 +1139,19 @@ isexe@^2.0.0:
|
|||||||
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
|
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
|
||||||
integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=
|
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:
|
js-tokens@^4.0.0:
|
||||||
version "4.0.0"
|
version "4.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
|
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
|
||||||
|
Loading…
Reference in New Issue
Block a user