URL encoding bugfix and add more tests.

pull/16/head
Kegan Dougal 2014-11-04 17:48:47 +00:00
parent a70765ed90
commit 4facbe02fb
2 changed files with 41 additions and 7 deletions

View File

@ -267,7 +267,7 @@ angular.module('matrixService', [])
// get room state for a specific room // get room state for a specific room
roomState: function(room_id) { roomState: function(room_id) {
var path = "/rooms/" + room_id + "/state"; var path = "/rooms/" + encodeURIComponent(room_id) + "/state";
return doRequest("GET", path); return doRequest("GET", path);
}, },

View File

@ -1,5 +1,5 @@
describe('MatrixService', function() { describe('MatrixService', function() {
var scope, httpBackend, createController; var scope, httpBackend;
var BASE = "http://example.com"; var BASE = "http://example.com";
var PREFIX = "/_matrix/client/api/v1"; var PREFIX = "/_matrix/client/api/v1";
var URL = BASE + PREFIX; var URL = BASE + PREFIX;
@ -7,7 +7,7 @@ describe('MatrixService', function() {
beforeEach(module('matrixService')); beforeEach(module('matrixService'));
beforeEach(inject(function($rootScope, $httpBackend, $controller) { beforeEach(inject(function($rootScope, $httpBackend) {
httpBackend = $httpBackend; httpBackend = $httpBackend;
scope = $rootScope; scope = $rootScope;
})); }));
@ -17,6 +17,40 @@ describe('MatrixService', function() {
httpBackend.verifyNoOutstandingRequest(); 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) { it('should be able to GET /rooms/$roomid/state', inject(function(matrixService) {
matrixService.setConfig({ matrixService.setConfig({
access_token: "foobar", access_token: "foobar",
@ -26,8 +60,8 @@ describe('MatrixService', function() {
expect(response.data).toEqual([]); expect(response.data).toEqual([]);
}); });
httpBackend.expect('GET', httpBackend.expectGET(
URL + "/rooms/" + roomId + "/state?access_token=foobar") URL + "/rooms/" + encodeURIComponent(roomId) + "/state?access_token=foobar")
.respond([]); .respond([]);
httpBackend.flush(); httpBackend.flush();
})); }));
@ -41,7 +75,7 @@ describe('MatrixService', function() {
expect(response.data).toEqual({}); expect(response.data).toEqual({});
}); });
httpBackend.expect('POST', httpBackend.expectPOST(
URL + "/join/" + encodeURIComponent(roomId) + "?access_token=foobar") URL + "/join/" + encodeURIComponent(roomId) + "?access_token=foobar")
.respond({}); .respond({});
httpBackend.flush(); httpBackend.flush();
@ -56,7 +90,7 @@ describe('MatrixService', function() {
expect(response.data).toEqual({}); expect(response.data).toEqual({});
}); });
httpBackend.expect('POST', httpBackend.expectPOST(
URL + "/rooms/" + encodeURIComponent(roomId) + "/join?access_token=foobar") URL + "/rooms/" + encodeURIComponent(roomId) + "/join?access_token=foobar")
.respond({}); .respond({});
httpBackend.flush(); httpBackend.flush();