From: kharhamel Date: Mon, 6 Apr 2020 13:48:19 +0000 (+0200) Subject: added jasmine in the back X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=ded19549c78433463710f8dbbf8d0cfde9d9d3de;p=libreadventure.git added jasmine in the back --- diff --git a/.github/workflows/continuous_integration.yml b/.github/workflows/continuous_integration.yml index f6f0ad7..302e50b 100644 --- a/.github/workflows/continuous_integration.yml +++ b/.github/workflows/continuous_integration.yml @@ -61,3 +61,7 @@ jobs: - name: "Lint" run: yarn run lint working-directory: "back" + + - name: "Jasmine" + run: yarn test + working-directory: "back" diff --git a/back/jasmine.json b/back/jasmine.json new file mode 100644 index 0000000..b51ed79 --- /dev/null +++ b/back/jasmine.json @@ -0,0 +1,5 @@ +{ + "spec_dir": "tests", + "spec_files": ["**/*[tT]est.ts"], + "stopSpecOnExpectationFailure": false +} \ No newline at end of file diff --git a/back/package.json b/back/package.json index 97d2896..4fe7681 100644 --- a/back/package.json +++ b/back/package.json @@ -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" } } diff --git a/back/src/Model/Websocket/ExtRoom.ts b/back/src/Model/Websocket/ExtRoom.ts index 03eb5e3..0cbe2f6 100644 --- a/back/src/Model/Websocket/ExtRoom.ts +++ b/back/src/Model/Websocket/ExtRoom.ts @@ -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 = []; if(mapPositionUserByRoom.get(data.roomId)){ diff --git a/back/src/Model/Websocket/Message.ts b/back/src/Model/Websocket/Message.ts index 3a53163..8e6f2c9 100644 --- a/back/src/Model/Websocket/Message.ts +++ b/back/src/Model/Websocket/Message.ts @@ -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; diff --git a/back/tests/MessageTest.ts b/back/tests/MessageTest.ts new file mode 100644 index 0000000..69d57fc --- /dev/null +++ b/back/tests/MessageTest.ts @@ -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")); + }) +}) \ No newline at end of file diff --git a/back/yarn.lock b/back/yarn.lock index 7ba7fbd..27f4503 100644 --- a/back/yarn.lock +++ b/back/yarn.lock @@ -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"