summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--syweb/webclient/test/unit/matrix-service.spec.js197
1 files changed, 191 insertions, 6 deletions
diff --git a/syweb/webclient/test/unit/matrix-service.spec.js b/syweb/webclient/test/unit/matrix-service.spec.js
index 29d2ca7be7..95a43057c4 100644
--- a/syweb/webclient/test/unit/matrix-service.spec.js
+++ b/syweb/webclient/test/unit/matrix-service.spec.js
@@ -17,7 +17,8 @@ describe('MatrixService', function() {
         httpBackend.verifyNoOutstandingRequest();
     });
 
-    it('should be able to POST /createRoom with an alias', inject(function(matrixService) {
+    it('should be able to POST /createRoom with an alias', inject(
+    function(matrixService) {
         matrixService.setConfig({
             access_token: "foobar",
             homeserver: "http://example.com"
@@ -51,7 +52,8 @@ describe('MatrixService', function() {
         httpBackend.flush();
     }));
     
-    it('should be able to GET /rooms/$roomid/state', inject(function(matrixService) {
+    it('should be able to GET /rooms/$roomid/state', inject(
+    function(matrixService) {
         matrixService.setConfig({
             access_token: "foobar",
             homeserver: "http://example.com"
@@ -61,7 +63,8 @@ describe('MatrixService', function() {
         });
 
         httpBackend.expectGET(
-            URL + "/rooms/" + encodeURIComponent(roomId) + "/state?access_token=foobar")
+            URL + "/rooms/" + encodeURIComponent(roomId) + 
+            "/state?access_token=foobar")
             .respond([]);
         httpBackend.flush();
     }));
@@ -76,12 +79,15 @@ describe('MatrixService', function() {
         });
 
         httpBackend.expectPOST(
-            URL + "/join/" + encodeURIComponent(roomId) + "?access_token=foobar")
+            URL + "/join/" + encodeURIComponent(roomId) + 
+            "?access_token=foobar",
+            {})
             .respond({});
         httpBackend.flush();
     }));
     
-    it('should be able to POST /rooms/$roomid/join', inject(function(matrixService) {
+    it('should be able to POST /rooms/$roomid/join', inject(
+    function(matrixService) {
         matrixService.setConfig({
             access_token: "foobar",
             homeserver: "http://example.com"
@@ -91,7 +97,186 @@ describe('MatrixService', function() {
         });
 
         httpBackend.expectPOST(
-            URL + "/rooms/" + encodeURIComponent(roomId) + "/join?access_token=foobar")
+            URL + "/rooms/" + encodeURIComponent(roomId) + 
+            "/join?access_token=foobar",
+            {})
+            .respond({});
+        httpBackend.flush();
+    }));
+    
+    it('should be able to POST /rooms/$roomid/invite', inject(
+    function(matrixService) {
+        matrixService.setConfig({
+            access_token: "foobar",
+            homeserver: "http://example.com"
+        });
+        var inviteUserId = "@user:example.com";
+        matrixService.invite(roomId, inviteUserId).then(function(response) {
+            expect(response.data).toEqual({});
+        });
+
+        httpBackend.expectPOST(
+            URL + "/rooms/" + encodeURIComponent(roomId) + 
+            "/invite?access_token=foobar",
+            {
+                user_id: inviteUserId
+            })
+            .respond({});
+        httpBackend.flush();
+    }));
+    
+    it('should be able to POST /rooms/$roomid/leave', inject(
+    function(matrixService) {
+        matrixService.setConfig({
+            access_token: "foobar",
+            homeserver: "http://example.com"
+        });
+        matrixService.leave(roomId).then(function(response) {
+            expect(response.data).toEqual({});
+        });
+
+        httpBackend.expectPOST(
+            URL + "/rooms/" + encodeURIComponent(roomId) + 
+            "/leave?access_token=foobar",
+            {})
+            .respond({});
+        httpBackend.flush();
+    }));
+    
+    it('should be able to POST /rooms/$roomid/ban', inject(
+    function(matrixService) {
+        matrixService.setConfig({
+            access_token: "foobar",
+            homeserver: "http://example.com"
+        });
+        var userId = "@example:example.com";
+        var reason = "Because.";
+        matrixService.ban(roomId, userId, reason).then(function(response) {
+            expect(response.data).toEqual({});
+        });
+
+        httpBackend.expectPOST(
+            URL + "/rooms/" + encodeURIComponent(roomId) + 
+            "/ban?access_token=foobar",
+            {
+                user_id: userId,
+                reason: reason
+            })
+            .respond({});
+        httpBackend.flush();
+    }));
+    
+    it('should be able to GET /directory/room/$alias', inject(
+    function(matrixService) {
+        matrixService.setConfig({
+            access_token: "foobar",
+            homeserver: "http://example.com"
+        });
+        var alias = "#test:example.com";
+        var roomId = "!wefuhewfuiw:example.com";
+        matrixService.resolveRoomAlias(alias).then(function(response) {
+            expect(response.data).toEqual({
+                room_id: roomId
+            });
+        });
+
+        httpBackend.expectGET(
+            URL + "/directory/room/" + encodeURIComponent(alias) +
+                    "?access_token=foobar")
+            .respond({
+                room_id: roomId
+            });
+        httpBackend.flush();
+    }));
+    
+    it('should be able to send m.room.name', inject(function(matrixService) {
+        matrixService.setConfig({
+            access_token: "foobar",
+            homeserver: "http://example.com"
+        });
+        var roomId = "!fh38hfwfwef:example.com";
+        var name = "Room Name";
+        matrixService.setName(roomId, name).then(function(response) {
+            expect(response.data).toEqual({});
+        });
+
+        httpBackend.expectPUT(
+            URL + "/rooms/" + encodeURIComponent(roomId) + 
+            "/state/m.room.name?access_token=foobar",
+            {
+                name: name
+            })
+            .respond({});
+        httpBackend.flush();
+    }));
+    
+    it('should be able to send m.room.topic', inject(function(matrixService) {
+        matrixService.setConfig({
+            access_token: "foobar",
+            homeserver: "http://example.com"
+        });
+        var roomId = "!fh38hfwfwef:example.com";
+        var topic = "A room topic can go here.";
+        matrixService.setTopic(roomId, topic).then(function(response) {
+            expect(response.data).toEqual({});
+        });
+
+        httpBackend.expectPUT(
+            URL + "/rooms/" + encodeURIComponent(roomId) + 
+            "/state/m.room.topic?access_token=foobar",
+            {
+                topic: topic
+            })
+            .respond({});
+        httpBackend.flush();
+    }));
+    
+    it('should be able to send generic state events without a state key', inject(
+    function(matrixService) {
+        matrixService.setConfig({
+            access_token: "foobar",
+            homeserver: "http://example.com"
+        });
+        var roomId = "!fh38hfwfwef:example.com";
+        var eventType = "com.example.events.test";
+        var content = {
+            testing: "1 2 3"
+        };
+        matrixService.sendStateEvent(roomId, eventType, content).then(
+        function(response) {
+            expect(response.data).toEqual({});
+        });
+
+        httpBackend.expectPUT(
+            URL + "/rooms/" + encodeURIComponent(roomId) + "/state/" + 
+            encodeURIComponent(eventType) + "?access_token=foobar",
+            content)
+            .respond({});
+        httpBackend.flush();
+    }));
+    
+    it('should be able to send generic state events with a state key', inject(
+    function(matrixService) {
+        matrixService.setConfig({
+            access_token: "foobar",
+            homeserver: "http://example.com"
+        });
+        var roomId = "!fh38hfwfwef:example.com";
+        var eventType = "com.example.events.test";
+        var content = {
+            testing: "1 2 3"
+        };
+        var stateKey = "version1";
+        matrixService.sendStateEvent(roomId, eventType, content, stateKey).then(
+        function(response) {
+            expect(response.data).toEqual({});
+        });
+
+        httpBackend.expectPUT(
+            URL + "/rooms/" + encodeURIComponent(roomId) + "/state/" + 
+            encodeURIComponent(eventType) + "/" + encodeURIComponent(stateKey)+
+            "?access_token=foobar",
+            content)
             .respond({});
         httpBackend.flush();
     }));