Gitter migration: Point people to app.gitter.im (rollout pt. 1)
[gitter.git] / public / js / utils / valid-room-uri-test.js
blobb4abdb8a93b6b2663ba036d2c0dafeb5741ec589
1 'use strict';
2 /* eslint-disable jest/valid-title */
4 var isValidRoomUri = require('./valid-room-uri');
5 var RESERVED = require('gitter-web-validators/lib/reserved-namespaces').list;
6 var RESERVED_SUB = require('gitter-web-validators/lib/reserved-sub-namespaces').list;
7 var assert = require('assert');
9 function test(name, expected) {
10   expected = typeof expected === 'undefined' ? true : expected;
11   var result = isValidRoomUri(name);
12   // keeping this as it is useful for seeing which one actually broke
13   //if (result !== expected) {
14   //  console.log(name);
15   //}
16   assert.equal(result, expected);
19 describe('valid-room-uri', function() {
20   it('rejects vanity keywords', function() {
21     RESERVED.forEach(function(keyword) {
22       test('/' + keyword, false);
23     });
24     RESERVED_SUB.forEach(function(keyword) {
25       test('/foo/' + keyword, false);
26     });
27   });
29   it("accepts rooms with vanity keywords, but aren't vanity keyworkds", function() {
30     test('/aboutandrew');
31     test('/apiguy');
32     test('/aboutandrew?test=true');
33     test('/apiguy?test=true');
34     test('/aboutandrew/roomname');
35     test('/aboutandrew/topicsname');
36   });
38   it('rejects undefined and empty string', function() {
39     test('     ', false);
40     test(null, false);
41     test(undefined, false);
42     test('', false);
43     test('a', false);
44   });
46   it('rejects archive links', function() {
47     test('/gitterHQ/gitter/archives/all', false);
48     test('/gitterHQ/gitter/archives/2014/12/11', false);
49     test('/gitterHQ/gitter/archives/all?test=true', false);
50     test('/gitterHQ/gitter/archives/2014/12/11?test=true', false);
51   });
53   it('accepts room URIs', function() {
54     test('/i-love-cats');
55     test('/i-love-cats/Lobby');
56     test('/i-love-cats/community');
57     test('/gitterHQ');
58     test('/gitterHQ/gitter');
59     test('/gitterHQ/gitter/channel');
60     test('/gitterHQ?test=true');
61     test('/gitterHQ/gitter?test=true');
62     test('/gitterHQ/gitter/channel?test=true');
63   });
65   /**
66    * https://github.com/troupe/gitter-webapp/issues/683
67    */
68   it('should detect orgs with dashes in their names', function() {
69     test('/orgs/dev-ua/rooms', false);
70   });
72   /**
73    * https://github.com/troupe/gitter-webapp/issues/683
74    */
75   it('should detect orgs community with underscores in their names', function() {
76     test('/orgs/dev_ua/rooms', false);
77   });
79   /**
80   /**
81    * https://github.com/troupe/gitter-webapp/issues/683
82    */
83   it('should anything under /orgs/', function() {
84     test('/orgs/blah/blah/blah', false);
85   });
87   /**
88    *
89    */
90   it.skip('should ensure that org names do not have underscores in them', function() {
91     test('/gitter_hq', false);
92   });
93 });