From 0881a8ae6f6468af8345fc9e6e46bdb32dfb405b Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 5 Nov 2014 12:32:28 +0000 Subject: [PATCH] Add more tests and a TODO. --- .../test/unit/matrix-service.spec.js | 57 ++++++++++++++++++- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/syweb/webclient/test/unit/matrix-service.spec.js b/syweb/webclient/test/unit/matrix-service.spec.js index ed290f2ff..2ca9a2432 100644 --- a/syweb/webclient/test/unit/matrix-service.spec.js +++ b/syweb/webclient/test/unit/matrix-service.spec.js @@ -231,14 +231,14 @@ describe('MatrixService', function() { httpBackend.flush(); })); - xit('should be able to send generic state events without a state key', inject( + 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:special@characters"; + var eventType = "com.example.events.test"; var content = { testing: "1 2 3" }; @@ -255,6 +255,8 @@ describe('MatrixService', function() { httpBackend.flush(); })); + // TODO: Skipped since the webclient is purposefully broken so as not to + // 500 matrix.org xit('should be able to send generic state events with a state key', inject( function(matrixService) { matrixService.setConfig({ @@ -280,4 +282,55 @@ describe('MatrixService', function() { .respond({}); httpBackend.flush(); })); + + it('should be able to PUT generic events ', inject( + function(matrixService) { + matrixService.setConfig({ + access_token: "foobar", + homeserver: "http://example.com" + }); + var roomId = "!fh38hfwfwef:example.com"; + var eventType = "com.example.events.test"; + var txnId = "42"; + var content = { + testing: "1 2 3" + }; + matrixService.sendEvent(roomId, eventType, txnId, content).then( + function(response) { + expect(response.data).toEqual({}); + }); + + httpBackend.expectPUT( + URL + "/rooms/" + encodeURIComponent(roomId) + "/send/" + + encodeURIComponent(eventType) + "/" + encodeURIComponent(txnId)+ + "?access_token=foobar", + content) + .respond({}); + httpBackend.flush(); + })); + + it('should be able to PUT text messages ', inject( + function(matrixService) { + matrixService.setConfig({ + access_token: "foobar", + homeserver: "http://example.com" + }); + var roomId = "!fh38hfwfwef:example.com"; + var body = "ABC 123"; + matrixService.sendTextMessage(roomId, body).then( + function(response) { + expect(response.data).toEqual({}); + }); + + httpBackend.expectPUT( + new RegExp(URL + "/rooms/" + encodeURIComponent(roomId) + + "/send/m.room.message/(.*)" + + "?access_token=foobar"), + { + body: body, + msgtype: "m.text" + }) + .respond({}); + httpBackend.flush(); + })); });