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({
17 troupe1: { users: ['user1', 'user2', 'user3'] }
20 describe('updateModeForUserInRoom', function() {
21 describe('default', function() {
22 [null, 'all', 'announcement', 'mute'].forEach(function(defaultMode) {
24 "should handle updating the user to the user default of '" + defaultMode + "'",
26 var user1 = fixture.user1;
27 var userId1 = user1._id;
28 var troupeId1 = fixture.troupe1._id;
31 ? userDefaultFlagsUpdateService.updateDefaultModeForUser(user1, defaultMode, false)
35 return userRoomModeUpdateService.setModeForUserInRoom(
42 return roomMembershipService.getMembershipDetails(userId1, troupeId1);
44 .then(function(details) {
45 assert.strictEqual(details.default, true);
46 assert.strictEqual(details.lurk, defaultMode === 'mute');
48 assert.strictEqual(details.mode, defaultMode);
50 assert.strictEqual(details.mode, 'all');
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)
68 return roomMembershipService.getMembershipDetails(userId1, troupeId1);
70 .then(function(details) {
71 assert.strictEqual(details.default, false);
72 assert.strictEqual(details.lurk, mode === 'mute');
73 assert.strictEqual(details.mode, mode);