1 /*jslint node:true, unused:true*/
2 /*global describe:true, it:true */
5 var assert = require('assert');
6 var fixtureLoader = require('gitter-web-test-utils/lib/test-fixtures');
8 var autoLurkerService = require('../lib/auto-lurker-service');
9 var recentRoomService = require('../lib/recent-room-service');
10 var roomMembershipService = require('../lib/room-membership-service');
11 var roomService = require('../lib/room-service');
13 describe('auto-lurker-service', function() {
14 describe('#findLurkCandidates', function() {
15 var fixture = fixtureLoader.setup({
17 troupe1: { users: ['user1'], lastAccessTime: false },
18 troupe2: { users: ['user1'], lastAccessTime: false }
21 it('should return a lurk candidate', function() {
22 var tenDaysAgo = new Date(Date.now() - 86400000 * 10);
23 return recentRoomService
24 .saveLastVisitedTroupeforUserId(fixture.user1.id, fixture.troupe1.id, {
25 lastAccessTime: tenDaysAgo
28 return autoLurkerService.findLurkCandidates(fixture.troupe1, { minTimeInDays: 1 });
30 .then(function(candidates) {
31 assert.strictEqual(candidates.length, 1);
33 assert.equal(candidates[0].userId, fixture.user1.id);
34 assert.equal(candidates[0].lastAccessTime.valueOf(), tenDaysAgo.valueOf());
38 it('should return a lurk candidate with notify settings', function() {
39 var tenDaysAgo = new Date(Date.now() - 86400000 * 10);
40 return roomMembershipService
41 .setMembershipMode(fixture.user1.id, fixture.troupe1.id, 'all')
43 return recentRoomService.saveLastVisitedTroupeforUserId(
46 { lastAccessTime: tenDaysAgo }
50 return autoLurkerService.findLurkCandidates(fixture.troupe1, { minTimeInDays: 1 });
52 .then(function(candidates) {
53 assert.strictEqual(candidates.length, 1);
55 assert.equal(candidates[0].userId, fixture.user1.id);
56 assert.equal(candidates[0].lastAccessTime.valueOf(), tenDaysAgo.valueOf());
60 it('should return a lurk candidate with notify settings', function() {
61 var tenDaysAgo = new Date(Date.now() - 86400000 * 10);
62 return roomMembershipService
63 .setMembershipMode(fixture.user1.id, fixture.troupe1.id, 'all')
65 return recentRoomService.saveLastVisitedTroupeforUserId(
68 { lastAccessTime: tenDaysAgo }
72 return autoLurkerService.findLurkCandidates(fixture.troupe1, { minTimeInDays: 1 });
74 .then(function(candidates) {
75 assert.strictEqual(candidates.length, 1);
77 assert.equal(candidates[0].userId, fixture.user1.id);
78 assert.equal(candidates[0].lastAccessTime.valueOf(), tenDaysAgo.valueOf());
82 it('should not return fully lurked candidates', function() {
83 var tenDaysAgo = new Date(Date.now() - 86400000 * 10);
84 return roomMembershipService
85 .setMembershipMode(fixture.user1.id, fixture.troupe1.id, 'mention')
87 return recentRoomService.saveLastVisitedTroupeforUserId(
90 { lastAccessTime: tenDaysAgo }
94 return autoLurkerService.findLurkCandidates(fixture.troupe1, { minTimeInDays: 1 });
96 .then(function(candidates) {
97 assert.strictEqual(candidates.length, 1);
99 assert.equal(candidates[0].userId, fixture.user1.id);
100 assert.equal(candidates[0].lastAccessTime.valueOf(), tenDaysAgo.valueOf());
104 it('should identify users for lurk based on the date they were added to the room if they have not logged in', function() {
105 var tenDaysAgo = new Date(Date.now() - 86400000 * 10);
106 return roomService.testOnly
107 .updateUserDateAdded(fixture.user1.id, fixture.troupe2.id, tenDaysAgo)
109 return autoLurkerService.findLurkCandidates(fixture.troupe2, { minTimeInDays: 1 });
111 .then(function(candidates) {
112 assert.strictEqual(candidates.length, 1);
113 assert.equal(candidates[0].userId, fixture.user1.id);
114 assert.strictEqual(candidates[0].lastAccessTime.valueOf(), tenDaysAgo.valueOf());
118 it('should ignore date added if the user has accessed the room since then', function() {
119 var tenDaysAgo = new Date(Date.now() - 86400000 * 10);
120 var twoDaysAgo = new Date(Date.now() - 86400000 * 2);
122 return roomService.testOnly
123 .updateUserDateAdded(fixture.user1.id, fixture.troupe2.id, tenDaysAgo)
125 return recentRoomService.saveLastVisitedTroupeforUserId(
128 { lastAccessTime: twoDaysAgo }
132 return autoLurkerService.findLurkCandidates(fixture.troupe2, { minTimeInDays: 1 });
134 .then(function(candidates) {
135 assert.strictEqual(candidates.length, 1);
136 assert.equal(candidates[0].userId, fixture.user1.id);
137 assert.strictEqual(candidates[0].lastAccessTime.valueOf(), twoDaysAgo.valueOf());
142 describe('#autoLurkInactiveUsers', function() {
143 var fixture = fixtureLoader.setup({
145 troupe1: { users: ['user1'], lastAccessTime: false }
148 it('should return a lurk candidate', function() {
149 var tenDaysAgo = new Date(Date.now() - 86400000 * 10);
150 return recentRoomService
151 .saveLastVisitedTroupeforUserId(fixture.user1.id, fixture.troupe1.id, {
152 lastAccessTime: tenDaysAgo
155 return autoLurkerService.autoLurkInactiveUsers(fixture.troupe1, { minTimeInDays: 1 });
159 roomMembershipService.getMembershipMode(fixture.user1.id, fixture.troupe1.id),
160 roomMembershipService.getMemberLurkStatus(fixture.troupe1.id, fixture.user1.id)
163 .spread(function(settings, lurkStatus) {
164 assert.strictEqual(settings, 'mute');
165 assert.strictEqual(true, lurkStatus);
169 it('should return a lurk candidate with notify settings', function() {
170 var tenDaysAgo = new Date(Date.now() - 86400000 * 10);
171 return roomMembershipService
172 .setMembershipMode(fixture.user1.id, fixture.troupe1.id, 'mention')
174 return recentRoomService.saveLastVisitedTroupeforUserId(
177 { lastAccessTime: tenDaysAgo }
181 return autoLurkerService.autoLurkInactiveUsers(fixture.troupe1, { minTimeInDays: 1 });
185 roomMembershipService.getMembershipMode(fixture.user1.id, fixture.troupe1.id),
186 roomMembershipService.getMemberLurkStatus(fixture.troupe1.id, fixture.user1.id)
189 .spread(function(settings, lurkStatus) {
190 assert.strictEqual(settings, 'mute');
191 assert.strictEqual(true, lurkStatus);
195 it('should return a lurk candidate with notify settings', function() {
196 var tenDaysAgo = new Date(Date.now() - 86400000 * 10);
197 return roomMembershipService
198 .setMembershipMode(fixture.user1.id, fixture.troupe1.id, 'mute')
200 return recentRoomService.saveLastVisitedTroupeforUserId(
203 { lastAccessTime: tenDaysAgo }
207 return autoLurkerService.autoLurkInactiveUsers(fixture.troupe1, { minTimeInDays: 1 });
211 roomMembershipService.getMembershipMode(fixture.user1.id, fixture.troupe1.id),
212 roomMembershipService.getMemberLurkStatus(fixture.troupe1.id, fixture.user1.id)
215 .spread(function(settings, lurkStatus) {
216 assert.strictEqual(settings, 'mute');
217 assert.strictEqual(true, lurkStatus);