diff options
author | Kegan Dougal <kegan@matrix.org> | 2014-11-04 17:48:47 +0000 |
---|---|---|
committer | Kegan Dougal <kegan@matrix.org> | 2014-11-04 17:48:47 +0000 |
commit | 4facbe02fbe53aafebfd68d88ae09c9ae77f3cd3 (patch) | |
tree | f32e4dab0b461a21a3e1b964b82f8eafdfb5763a /syweb | |
parent | Add matrix-service unit tests. Update angular-mocks. (diff) | |
download | synapse-4facbe02fbe53aafebfd68d88ae09c9ae77f3cd3.tar.xz |
URL encoding bugfix and add more tests.
Diffstat (limited to 'syweb')
-rw-r--r-- | syweb/webclient/components/matrix/matrix-service.js | 2 | ||||
-rw-r--r-- | syweb/webclient/test/unit/matrix-service.spec.js | 46 |
2 files changed, 41 insertions, 7 deletions
diff --git a/syweb/webclient/components/matrix/matrix-service.js b/syweb/webclient/components/matrix/matrix-service.js index fedfb8910d..5b63fb4a3b 100644 --- a/syweb/webclient/components/matrix/matrix-service.js +++ b/syweb/webclient/components/matrix/matrix-service.js @@ -267,7 +267,7 @@ angular.module('matrixService', []) // get room state for a specific room roomState: function(room_id) { - var path = "/rooms/" + room_id + "/state"; + var path = "/rooms/" + encodeURIComponent(room_id) + "/state"; return doRequest("GET", path); }, diff --git a/syweb/webclient/test/unit/matrix-service.spec.js b/syweb/webclient/test/unit/matrix-service.spec.js index 3c5163e478..29d2ca7be7 100644 --- a/syweb/webclient/test/unit/matrix-service.spec.js +++ b/syweb/webclient/test/unit/matrix-service.spec.js @@ -1,5 +1,5 @@ describe('MatrixService', function() { - var scope, httpBackend, createController; + var scope, httpBackend; var BASE = "http://example.com"; var PREFIX = "/_matrix/client/api/v1"; var URL = BASE + PREFIX; @@ -7,7 +7,7 @@ describe('MatrixService', function() { beforeEach(module('matrixService')); - beforeEach(inject(function($rootScope, $httpBackend, $controller) { + beforeEach(inject(function($rootScope, $httpBackend) { httpBackend = $httpBackend; scope = $rootScope; })); @@ -17,6 +17,40 @@ describe('MatrixService', function() { httpBackend.verifyNoOutstandingRequest(); }); + it('should be able to POST /createRoom with an alias', inject(function(matrixService) { + matrixService.setConfig({ + access_token: "foobar", + homeserver: "http://example.com" + }); + var alias = "flibble"; + matrixService.create(alias).then(function(response) { + expect(response.data).toEqual({}); + }); + + httpBackend.expectPOST(URL + "/createRoom?access_token=foobar", + { + room_alias_name: alias + }) + .respond({}); + httpBackend.flush(); + })); + + it('should be able to GET /initialSync', inject(function(matrixService) { + matrixService.setConfig({ + access_token: "foobar", + homeserver: "http://example.com" + }); + var limit = 15; + matrixService.initialSync(limit).then(function(response) { + expect(response.data).toEqual([]); + }); + + httpBackend.expectGET( + URL + "/initialSync?access_token=foobar&limit=15") + .respond([]); + httpBackend.flush(); + })); + it('should be able to GET /rooms/$roomid/state', inject(function(matrixService) { matrixService.setConfig({ access_token: "foobar", @@ -26,8 +60,8 @@ describe('MatrixService', function() { expect(response.data).toEqual([]); }); - httpBackend.expect('GET', - URL + "/rooms/" + roomId + "/state?access_token=foobar") + httpBackend.expectGET( + URL + "/rooms/" + encodeURIComponent(roomId) + "/state?access_token=foobar") .respond([]); httpBackend.flush(); })); @@ -41,7 +75,7 @@ describe('MatrixService', function() { expect(response.data).toEqual({}); }); - httpBackend.expect('POST', + httpBackend.expectPOST( URL + "/join/" + encodeURIComponent(roomId) + "?access_token=foobar") .respond({}); httpBackend.flush(); @@ -56,7 +90,7 @@ describe('MatrixService', function() { expect(response.data).toEqual({}); }); - httpBackend.expect('POST', + httpBackend.expectPOST( URL + "/rooms/" + encodeURIComponent(roomId) + "/join?access_token=foobar") .respond({}); httpBackend.flush(); |