summary refs log tree commit diff
path: root/syweb/webclient/test/unit/event-stream-service.spec.js
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2014-11-14 17:30:17 +0000
committerKegan Dougal <kegan@matrix.org>2014-11-14 17:30:17 +0000
commit44a24605ad74871d22cfc42654bce34452e21dc7 (patch)
treec76f2453fa29377a11a1e9f4341d8c8c948e842e /syweb/webclient/test/unit/event-stream-service.spec.js
parentUnbreak tab complete... (diff)
downloadsynapse-44a24605ad74871d22cfc42654bce34452e21dc7.tar.xz
Add event-stream-service unit tests.
Diffstat (limited to 'syweb/webclient/test/unit/event-stream-service.spec.js')
-rw-r--r--syweb/webclient/test/unit/event-stream-service.spec.js80
1 files changed, 80 insertions, 0 deletions
diff --git a/syweb/webclient/test/unit/event-stream-service.spec.js b/syweb/webclient/test/unit/event-stream-service.spec.js
new file mode 100644
index 0000000000..6fd7693a70
--- /dev/null
+++ b/syweb/webclient/test/unit/event-stream-service.spec.js
@@ -0,0 +1,80 @@
+describe('EventStreamService', function() {
+    var q, scope;
+
+    var testInitialSync, testEventStream;
+
+    var matrixService = {
+        initialSync: function(limit, feedback) {
+            var defer = q.defer();
+            defer.resolve(testInitialSync);
+            return defer.promise;
+        },
+        getEventStream: function(from, svrTimeout, cliTimeout) {
+            var defer = q.defer();
+            defer.resolve(testEventStream);
+            return defer.promise;
+        }
+    };
+    
+    var eventHandlerService = {
+        handleInitialSyncDone: function(response) {
+        
+        },
+        
+        handleEvents: function(chunk, isLive) {
+        
+        }
+    };
+
+    // setup the dependencies
+    beforeEach(function() {
+    
+        // reset test data
+        testInitialSync = {
+            data: {
+                end: "foo",
+                presence: [],
+                rooms: []
+            }
+        };
+        testEventStream = {
+            data: {
+                start: "foostart",
+                end: "fooend",
+                chunk: []
+            }
+        };
+    
+        // dependencies
+        module(function ($provide) {
+          $provide.value('matrixService', matrixService);
+          $provide.value('eventHandlerService', eventHandlerService);
+        });
+        
+        // tested service
+        module('eventStreamService');
+    });
+    
+    beforeEach(inject(function($q, $rootScope) {
+        q = $q;
+        scope = $rootScope;
+    }));
+
+    it('should start with /initialSync then go onto /events', inject(
+    function(eventStreamService) {
+        spyOn(eventHandlerService, "handleInitialSyncDone");
+        spyOn(eventHandlerService, "handleEvents");
+        eventStreamService.resume();
+        scope.$apply(); // initialSync request
+        expect(eventHandlerService.handleInitialSyncDone).toHaveBeenCalledWith(testInitialSync);
+        expect(eventHandlerService.handleEvents).toHaveBeenCalledWith(testEventStream.data.chunk, true);
+    }));
+    
+    it('should use the end token in /initialSync for the next /events request', inject(
+    function(eventStreamService) {
+        spyOn(matrixService, "getEventStream").and.callThrough();
+        eventStreamService.resume();
+        scope.$apply(); // initialSync request
+        expect(matrixService.getEventStream).toHaveBeenCalledWith("foo", eventStreamService.SERVER_TIMEOUT, eventStreamService.CLIENT_TIMEOUT);
+    }));
+});