3 var assert = require('assert');
4 var Promise = require('bluebird');
5 var fixtureLoader = require('gitter-web-test-utils/lib/test-fixtures');
7 var userDefaultFlagsUpdateService = require('../lib/user-default-flags-update-service');
8 var userDefaultFlagsService = require('../lib/user-default-flags-service');
9 var roomMembershipService = require('../lib/room-membership-service');
10 var roomMembershipFlags = require('../lib/room-membership-flags');
11 var roomService = require('../lib/room-service');
13 describe('user-default-flags-update-service', function() {
14 describe('#slow', function() {
15 var fixture = fixtureLoader.setup({
21 githubType: 'USER_CHANNEL'
25 githubType: 'USER_CHANNEL'
29 githubType: 'USER_CHANNEL'
33 describe('updateDefaultModeForUser', function() {
34 it('should affect future room join operations', function() {
35 var user1 = fixture.user1;
36 var troupe1 = fixture.troupe1;
37 var userId1 = user1._id;
38 var troupeId1 = troupe1._id;
40 return roomMembershipService
41 .removeRoomMembers(troupeId1, [userId1])
43 return userDefaultFlagsUpdateService.updateDefaultModeForUser(user1, 'mute');
46 return userDefaultFlagsService.getDefaultFlagsForUserId(userId1);
48 .then(function(flags) {
49 var mode = roomMembershipFlags.getModeFromFlags(flags);
52 return roomService.joinRoom(troupe1, user1, {});
55 return roomMembershipService.getMembershipDetails(userId1, troupeId1);
57 .then(function(membershipDefaults) {
58 assert.strictEqual(membershipDefaults.mode, 'mute');
62 it('should update the rooms the user is currently in when they are default', function() {
63 var user1 = fixture.user1;
64 var userId1 = user1._id;
65 var troupeId1 = fixture.troupe1._id;
66 var troupeId2 = fixture.troupe2._id;
67 var troupeId3 = fixture.troupe3._id;
70 roomMembershipService.removeRoomMembers(troupeId1, [userId1]),
71 roomMembershipService.removeRoomMembers(troupeId2, [userId1]),
72 roomMembershipService.removeRoomMembers(troupeId3, [userId1])
76 roomMembershipService.addRoomMember(
79 roomMembershipFlags.getFlagsForMode('all', true)
81 roomMembershipService.addRoomMember(
84 roomMembershipFlags.getFlagsForMode('announcement', true)
86 roomMembershipService.addRoomMember(
89 roomMembershipFlags.getFlagsForMode('mute', true)
94 return userDefaultFlagsUpdateService.updateDefaultModeForUser(user1, 'mute', false); // Only override defaults
98 roomMembershipService.getMembershipDetails(userId1, troupeId1),
99 roomMembershipService.getMembershipDetails(userId1, troupeId2),
100 roomMembershipService.getMembershipDetails(userId1, troupeId3),
101 function(d1, d2, d3) {
102 assert.strictEqual(d1.mode, 'mute');
103 assert.strictEqual(d2.mode, 'mute');
104 assert.strictEqual(d3.mode, 'mute');
110 it('should not update the rooms the user is currently in when they are default', function() {
111 var user1 = fixture.user1;
112 var userId1 = user1._id;
113 var troupeId1 = fixture.troupe1._id;
114 var troupeId2 = fixture.troupe2._id;
115 var troupeId3 = fixture.troupe3._id;
118 roomMembershipService.removeRoomMembers(troupeId1, [userId1]),
119 roomMembershipService.removeRoomMembers(troupeId2, [userId1]),
120 roomMembershipService.removeRoomMembers(troupeId3, [userId1])
124 roomMembershipService.addRoomMember(
127 roomMembershipFlags.getFlagsForMode('all', false)
129 roomMembershipService.addRoomMember(
132 roomMembershipFlags.getFlagsForMode('announcement', false)
134 roomMembershipService.addRoomMember(
137 roomMembershipFlags.getFlagsForMode('mute', false)
142 return userDefaultFlagsUpdateService.updateDefaultModeForUser(user1, 'mute', false); // Only override defaults
146 roomMembershipService.getMembershipDetails(userId1, troupeId1),
147 roomMembershipService.getMembershipDetails(userId1, troupeId2),
148 roomMembershipService.getMembershipDetails(userId1, troupeId3),
149 function(d1, d2, d3) {
150 assert.strictEqual(d1.mode, 'all');
151 assert.strictEqual(d2.mode, 'announcement');
152 assert.strictEqual(d3.mode, 'mute');