added jasmine in the back
authorkharhamel <oognic@gmail.com>
Mon, 6 Apr 2020 13:48:19 +0000 (15:48 +0200)
committerkharhamel <oognic@gmail.com>
Mon, 6 Apr 2020 13:48:19 +0000 (15:48 +0200)
.github/workflows/continuous_integration.yml
back/jasmine.json [new file with mode: 0644]
back/package.json
back/src/Model/Websocket/ExtRoom.ts
back/src/Model/Websocket/Message.ts
back/tests/MessageTest.ts [new file with mode: 0644]
back/yarn.lock

index f6f0ad7e59f14de2530efa91e5681eec8df42a63..302e50b739953fa66345cddc3d5fab6378096afd 100644 (file)
@@ -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 (file)
index 0000000..b51ed79
--- /dev/null
@@ -0,0 +1,5 @@
+{
+  "spec_dir": "tests",
+  "spec_files": ["**/*[tT]est.ts"],
+  "stopSpecOnExpectationFailure": false
+}
\ No newline at end of file
index 97d289689aaaeac292cd60075bf92fffc288eacf..4fe7681d865623409e73601363249dafbf349e6f 100644 (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": {
     "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"
   }
 }
index 03eb5e331deff36bdde7d2960fdeda5e3414d778..0cbe2f61e086e9f8c9e43c45bbe8d722c2227d34 100644 (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)){
index 3a53163f3d6b5ff239fe6cdee1f53c2a42b8ff95..8e6f2c9a0748cc18360477e26e8d8ea1b1fc1a15 100644 (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;
diff --git a/back/tests/MessageTest.ts b/back/tests/MessageTest.ts
new file mode 100644 (file)
index 0000000..69d57fc
--- /dev/null
@@ -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
index 7ba7fbdcdf4790067f1efd903bf34711ba1b32af..27f4503ea6525c0108168fcbd1782652b82ce064 100644 (file)
   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"