Merge branch 'hotfix/21.56.9' into master
[gitter.git] / modules / rooms / test / room-removed-users-core-test.js
blob01d5769e46a236bc2a4295ae9cf130d05b39cba7
1 'use strict';
3 var assert = require('assert');
4 var ObjectID = require('mongodb').ObjectID;
5 var roomRemovedUserCore = require('../lib/room-removed-user-core');
6 var TroupeRemovedUser = require('gitter-web-persistence').TroupeRemovedUser;
8 describe('room-removed-users-core', function() {
9   describe('addRemovedUser', function() {
10     it('should record a removed user', function() {
11       var userId = new ObjectID();
12       var roomId = new ObjectID();
14       return roomRemovedUserCore
15         .addRemovedUser(roomId, userId)
16         .then(function() {
17           return TroupeRemovedUser.findOne({ troupeId: roomId, userId: userId })
18             .lean()
19             .exec();
20         })
21         .then(function(result) {
22           assert(result);
23           assert(Date.now() - result.date > 0);
24           assert(Date.now() - result.date < 1000);
25           assert.equal(String(result.userId), String(userId));
26           assert.equal(String(result.troupeId), String(roomId));
27         });
28     });
29   });
31   describe('addRemovedUsers', function() {
32     it('should record removed users', function() {
33       var userId1 = new ObjectID();
34       var userId2 = new ObjectID();
35       var roomId = new ObjectID();
37       return roomRemovedUserCore
38         .addRemovedUsers(roomId, [userId1, userId2])
39         .then(function() {
40           return TroupeRemovedUser.findOne({ troupeId: roomId, userId: userId1 })
41             .lean()
42             .exec();
43         })
44         .then(function(result) {
45           assert(result);
46           assert(Date.now() - result.date > 0);
47           assert(Date.now() - result.date < 1000);
48           assert.equal(String(result.userId), String(userId1));
49           assert.equal(String(result.troupeId), String(roomId));
51           return TroupeRemovedUser.findOne({ troupeId: roomId, userId: userId1 })
52             .lean()
53             .exec();
54         })
55         .then(function(result) {
56           assert(result);
57           assert(Date.now() - result.date > 0);
58           assert(Date.now() - result.date < 1000);
59           assert.equal(String(result.userId), String(userId1));
60           assert.equal(String(result.troupeId), String(roomId));
61         });
62     });
63   });
64 });