summary refs log tree commit diff
path: root/syweb/webclient/test/unit/notification-service.spec.js
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2014-11-14 11:16:50 +0000
committerMark Haines <mark.haines@matrix.org>2014-11-14 11:16:50 +0000
commite903c941cb1bed18026f00ed1d3495a8d172f13a (patch)
tree894da7441d913361b70da4cc13cd73ead86d2e67 /syweb/webclient/test/unit/notification-service.spec.js
parentRemove unused 'context' variables to appease pyflakes (diff)
parentAdd notification-service unit tests. (diff)
downloadsynapse-e903c941cb1bed18026f00ed1d3495a8d172f13a.tar.xz
Merge branch 'develop' into request_logging
Conflicts:
	setup.py
	synapse/storage/_base.py
	synapse/util/async.py
Diffstat (limited to 'syweb/webclient/test/unit/notification-service.spec.js')
-rw-r--r--syweb/webclient/test/unit/notification-service.spec.js78
1 files changed, 78 insertions, 0 deletions
diff --git a/syweb/webclient/test/unit/notification-service.spec.js b/syweb/webclient/test/unit/notification-service.spec.js
new file mode 100644
index 0000000000..4205ca0969
--- /dev/null
+++ b/syweb/webclient/test/unit/notification-service.spec.js
@@ -0,0 +1,78 @@
+describe('NotificationService', function() {
+
+    var userId = "@ali:matrix.org";
+    var displayName = "Alice M";
+    var bingWords = ["coffee","foo(.*)bar"]; // literal and wildcard
+
+    beforeEach(function() {
+        module('notificationService');
+    });
+    
+    // User IDs
+    
+    it('should bing on a user ID.', inject(
+    function(notificationService) {
+        expect(notificationService.containsBingWord(userId, displayName, 
+        bingWords, "Hello @ali:matrix.org, how are you?")).toEqual(true);
+    }));
+    
+    it('should bing on a partial user ID.', inject(
+    function(notificationService) {
+        expect(notificationService.containsBingWord(userId, displayName, 
+        bingWords, "Hello @ali, how are you?")).toEqual(true);
+    }));
+    
+    it('should bing on a case-insensitive user ID.', inject(
+    function(notificationService) {
+        expect(notificationService.containsBingWord(userId, displayName, 
+        bingWords, "Hello @AlI:matrix.org, how are you?")).toEqual(true);
+    }));
+    
+    // Display names
+    
+    it('should bing on a display name.', inject(
+    function(notificationService) {
+        expect(notificationService.containsBingWord(userId, displayName, 
+        bingWords, "Hello Alice M, how are you?")).toEqual(true);
+    }));
+    
+    it('should bing on a case-insensitive display name.', inject(
+    function(notificationService) {
+        expect(notificationService.containsBingWord(userId, displayName, 
+        bingWords, "Hello ALICE M, how are you?")).toEqual(true);
+    }));
+    
+    // Bing words
+    
+    it('should bing on a bing word.', inject(
+    function(notificationService) {
+        expect(notificationService.containsBingWord(userId, displayName, 
+        bingWords, "I really like coffee")).toEqual(true);
+    }));
+    
+    it('should bing on case-insensitive bing words.', inject(
+    function(notificationService) {
+        expect(notificationService.containsBingWord(userId, displayName, 
+        bingWords, "Coffee is great")).toEqual(true);
+    }));
+    
+    it('should bing on wildcard (.*) bing words.', inject(
+    function(notificationService) {
+        expect(notificationService.containsBingWord(userId, displayName, 
+        bingWords, "It was foomahbar I think.")).toEqual(true);
+    }));
+    
+    // invalid
+    
+    it('should gracefully handle bad input.', inject(
+    function(notificationService) {
+        expect(notificationService.containsBingWord(userId, displayName, 
+        bingWords, { "foo": "bar" })).toEqual(false);
+    }));
+    
+    it('should gracefully handle just a user ID.', inject(
+    function(notificationService) {
+        expect(notificationService.containsBingWord(userId, undefined, 
+        undefined, "Hello @ali:matrix.org, how are you?")).toEqual(true);
+    }));
+});