Merge branch 'hotfix/21.56.9' into master
[gitter.git] / modules / rooms / test / room-repo-service-test.js
blob1830e5b3c1b01765512ab79de8b20247034e3ad9
1 'use strict';
3 var fixtureLoader = require('gitter-web-test-utils/lib/test-fixtures');
4 var assert = require('assert');
5 var roomRepoService = require('../lib/room-repo-service');
7 describe('room-repo-service #slow', function() {
8   var fixture = fixtureLoader.setup({
9     troupe1: {},
10     troupe2: {},
11     troupe3: {},
12     troupe4: {
13       group: 'group1'
14     },
15     group1: {
16       securityDescriptor: {
17         type: 'GH_REPO',
18         admins: 'GH_REPO_PUSH',
19         linkPath: 'x/y'
20       }
21     },
22     troupe5: {
23       securityDescriptor: {
24         type: 'GH_REPO',
25         admins: 'GH_REPO_PUSH',
26         linkPath: '1/2'
27       }
28     },
29     troupe6: {
30       securityDescriptor: {
31         type: 'GH_REPO',
32         admins: 'GH_REPO_PUSH',
33         linkPath: '3/4'
34       },
35       group: 'group1'
36     },
37     troupe7: {
38       group: 'group2'
39     },
40     group2: {}
41   });
43   describe('findAssociatedGithubObjectForRoom', function() {
44     it('should deal with rooms with no backing object', function() {
45       return roomRepoService
46         .findAssociatedGithubObjectForRoom(fixture.troupe1)
47         .then(function(result) {
48           assert.deepEqual(result, null);
49         });
50     });
52     it('should deal with groups with no backing object', function() {
53       return roomRepoService
54         .findAssociatedGithubObjectForRoom(fixture.troupe7)
55         .then(function(result) {
56           assert.deepEqual(result, null);
57         });
58     });
60     it('should deal with rooms backed by a repo', function() {
61       return roomRepoService
62         .findAssociatedGithubObjectForRoom(fixture.troupe5)
63         .then(function(result) {
64           assert.deepEqual(result, {
65             type: 'GH_REPO',
66             linkPath: '1/2'
67           });
68         });
69     });
70     it('should deal with groups backed by a repo', function() {
71       return roomRepoService
72         .findAssociatedGithubObjectForRoom(fixture.troupe4)
73         .then(function(result) {
74           assert.deepEqual(result, {
75             type: 'GH_REPO',
76             linkPath: 'x/y'
77           });
78         });
79     });
80   });
82   describe('findAssociatedGithubRepoForRooms', function() {
83     it('should deal with no rooms', function() {
84       return roomRepoService.findAssociatedGithubRepoForRooms([]).then(function(result) {
85         assert.deepEqual(result, {});
86       });
87     });
89     it('should deal with one room, not successful', function() {
90       return roomRepoService
91         .findAssociatedGithubRepoForRooms([fixture.troupe1])
92         .then(function(result) {
93           assert.deepEqual(result, {});
94         });
95     });
97     it('should deal with one room, successful', function() {
98       return roomRepoService
99         .findAssociatedGithubRepoForRooms([fixture.troupe4])
100         .then(function(result) {
101           var expected = {};
102           expected[fixture.troupe4.id] = 'x/y';
103           assert.deepEqual(result, expected);
104         });
105     });
107     it('should deal with many rooms', function() {
108       return roomRepoService
109         .findAssociatedGithubRepoForRooms([fixture.troupe1, fixture.troupe2, fixture.troupe3])
110         .then(function(result) {
111           assert.deepEqual(result, {});
112         });
113     });
115     it('should deal with mixed rooms', function() {
116       return roomRepoService
117         .findAssociatedGithubRepoForRooms([fixture.troupe1, fixture.troupe4])
118         .then(function(result) {
119           var expected = {};
120           expected[fixture.troupe4.id] = 'x/y';
121           assert.deepEqual(result, expected);
122         });
123     });
125     it('should deal with mixed rooms, 2', function() {
126       return roomRepoService
127         .findAssociatedGithubRepoForRooms([
128           fixture.troupe1,
129           fixture.troupe4,
130           fixture.troupe5,
131           fixture.troupe6
132         ])
133         .then(function(result) {
134           var expected = {};
135           expected[fixture.troupe4.id] = 'x/y';
136           expected[fixture.troupe5.id] = '1/2';
137           expected[fixture.troupe6.id] = '3/4';
138           assert.deepEqual(result, expected);
139         });
140     });
141   });