Merge branch 'fix-ci-yaml-container-scanning' into 'develop'
[gitter.git] / modules / rooms / test / user-room-mode-update-service-test.js
blob03d168b4a3525a00141ca5cc98b9b4cc025c1685
1 'use strict';
3 var assert = require('assert');
4 var Promise = require('bluebird');
5 var fixtureLoader = require('gitter-web-test-utils/lib/test-fixtures');
7 var userRoomModeUpdateService = require('../lib/user-room-mode-update-service');
8 var userDefaultFlagsUpdateService = require('../lib/user-default-flags-update-service');
9 var roomMembershipService = require('../lib/room-membership-service');
11 describe('user-room-mode-update-service', function() {
12   describe('#slow', function() {
13     var fixture = fixtureLoader.setup({
14       user1: {},
15       user2: {},
16       user3: {},
17       troupe1: { users: ['user1', 'user2', 'user3'] }
18     });
20     describe('updateModeForUserInRoom', function() {
21       describe('default', function() {
22         [null, 'all', 'announcement', 'mute'].forEach(function(defaultMode) {
23           it(
24             "should handle updating the user to the user default of '" + defaultMode + "'",
25             function() {
26               var user1 = fixture.user1;
27               var userId1 = user1._id;
28               var troupeId1 = fixture.troupe1._id;
30               return (defaultMode
31                 ? userDefaultFlagsUpdateService.updateDefaultModeForUser(user1, defaultMode, false)
32                 : Promise.resolve()
33               )
34                 .then(function() {
35                   return userRoomModeUpdateService.setModeForUserInRoom(
36                     user1,
37                     troupeId1,
38                     'default'
39                   );
40                 })
41                 .then(function() {
42                   return roomMembershipService.getMembershipDetails(userId1, troupeId1);
43                 })
44                 .then(function(details) {
45                   assert.strictEqual(details.default, true);
46                   assert.strictEqual(details.lurk, defaultMode === 'mute');
47                   if (defaultMode) {
48                     assert.strictEqual(details.mode, defaultMode);
49                   } else {
50                     assert.strictEqual(details.mode, 'all');
51                   }
52                 });
53             }
54           );
55         });
56       });
58       describe('non-default', function() {
59         ['all', 'announcement', 'mute'].forEach(function(mode) {
60           it("should handle updating the user to '" + mode + "'", function() {
61             var user1 = fixture.user1;
62             var userId1 = user1._id;
63             var troupeId1 = fixture.troupe1._id;
65             return userRoomModeUpdateService
66               .setModeForUserInRoom(user1, troupeId1, mode)
67               .then(function() {
68                 return roomMembershipService.getMembershipDetails(userId1, troupeId1);
69               })
70               .then(function(details) {
71                 assert.strictEqual(details.default, false);
72                 assert.strictEqual(details.lurk, mode === 'mute');
73                 assert.strictEqual(details.mode, mode);
74               });
75           });
76         });
77       });
78     });
79   });
80 });